snoob dogg
snoob dogg

Reputation: 2865

Node.js : How to centralise npm modules ?

I've got some troubles installing node-canvas with npm on Windows. It conducted me to do a lot of tests, changing some env variables, parameters, etc...

What's very annoying is that anywhere I am on my hard-drive, If I execute 'npm install -g canvas' it will creates a folder 'node_modules' locally... I didn't noticed that immediately so now I've got some 'node_modules' folders a bit everywhere (boring) -_-' ! I thought it was only in users/user_name/appdata/roaming/npm ?

I read that most people prefers to install node's dependency in the projet folder. it probably explains npm acts like this. How to avoid that ?

Upvotes: 0

Views: 252

Answers (1)

Boshika Tara
Boshika Tara

Reputation: 274

There are a couple of reasons why people install node modules for the current working directory(project directory). The main reason being If there is something that you are only going to use in your specific project then you want to install node modules locally. Also, this helps with using the correct version for your specific project. The only time you should be installing npm modules globally is if they are being used by other things outside your current project. A good example of this is nodemon, it watches the files in the directory in which nodemon was started, and if any files changed, it will automatically restart the application. So for this, you could install globally

npm install -g nodemon

Of course, you can also just install it in your project directory

npm install --save-dev nodemon

Upvotes: 1

Related Questions