How Do I Install Package.json Dependencies In The Current Directory Using Npm
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
. How do I do this?
What I want
Lets say I have two widget
dependencies. I want to end up with a directory structure like this:
node_modules/
widgetA
widgetB
fooapp/
package.js
lib
..
What I get
when I run npm install fooapp/
I get this:
node_modules/
fooapp/
node_modules/
widgetA
widgetB
package.js
lib/
..
fooapp/
package.js
lib/
..
npm makes a copy of my app directory in the node_modules dir and installs the packages inside another node_modules directory.
I understand this makes sense for installing a package. But I don't require()
my web app inside of something else, I run it directly. I'm looking for a simple way to install my dependencies into a specific node_modules directory.
Answer
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
Related Questions
- → Cant run a migration when deploying. Laravel 5.2
- → Git deployment of October CMS site
- → Cannot deploy OctoberCMS to Google App Engine (Flex)
- → Laravel Deployment on Shared Hosting - 404 Error
- → No css/js or images found on heroku deployment octobercms
- → Correct deployment of structured data for Google rich cards
- → Removing # from URL does not work after deployment - HTTP 404
- → How do i make my react web appp to appear on google search?
- → javascript dyanmic table add / delete row
- → AngularJS loads index.html instead of template
- → Laravel 5 - PHP Fatal error: require(): Failed opening required vendor/autoload.php
- → What are the correct steps to deploy a production laravel 5.2 app?
- → Trying to connect the Shopify app using Shopify connect is throwing an error