How do I install package.json dependencies in the current directory using npm

前端 未结 3 1820
梦谈多话
梦谈多话 2020-12-07 07:48

I have a web app: fooapp. I have a package.json in the root. I want to install all the dependencies in a specific node_modules directory

相关标签:
3条回答
  • 2020-12-07 07:50

    Just execute

    sudo npm i --save
    

    That's all

    0 讨论(0)
  • 2020-12-07 07:53

    In my case I need to do

    sudo npm install  
    

    my project is inside /var/www so I also need to set proper permissions.

    0 讨论(0)
  • 2020-12-07 07:54

    Running:

    npm install
    

    from inside your app directory (i.e. where package.json is located) will install the dependencies for your app, rather than install it as a module, as described here. These will be placed in ./node_modules relative to your package.json file (it's actually slightly more complex than this, so check the npm docs here).

    You are free to move the node_modules dir to the parent dir of your app if you want, because node's 'require' mechanism understands this. However, if you want to update your app's dependencies with install/update, npm will not see the relocated 'node_modules' and will instead create a new dir, again relative to package.json.

    To prevent this, just create a symlink to the relocated node_modules from your app dir:

    ln -s ../node_modules node_modules
    
    0 讨论(0)
提交回复
热议问题