Hey everyone :-)
I've been using npm for a while now and usually install all my packages globally. Is this a recommended thing to do?
What possible side effects might this have?
What would you recommend? Everything global or local?
Thanks in advance :-)
As Lars said, it depends. If it's a CLI tool or something similar, it's usually installed globally (npm install -g). Your project's dependencies such as Express, passport, body-parser, ejs etc are installed locally (npm install).
I decide. Sometimes global and mostly local. Thinks like ts-node, ava, typescript are global and local. Than other thinks like expressjs, body-parser are always local.
So when a package has global use I install it global and when not I install it lokal.
What @fibric says. Additionaly, pay attention to what IDE do you use: sometimes they require a package to be installed specifically locally or globally.
./node_modules of the current package root.-g): puts stuff in /usr/local or wherever node is installed.require() it.npm link.reference : docs.npmjs.com/files/folders
Denny Trebbin
Lead Fullstack Developer. Experimenting with bleeding-edge tech. Irregularly DJ. Hobby drone pilot. Amateur photographer.
I don't install packages globally. Usually each package I install belongs to a project. So I install it locally as a dependency. If a package offers CLI functionality I add it in
package.jsonunderscriptssection.{ ..., "scripts": { "webpack": "webpack", "start": "node .", ... }, ..., }Now I can run its CLI features.
npm run webpack. If needed I addbashorzshaliases to get rid of ever repeatingnpm runprefix. I do this because each package targets a specific minimum node version. When ever I am forced or willing to upgradenodeI must not care for globally installed packages unless installed globally, of cause. Some few CLI tools require other global CLI tools. Only in his case I am forced to install a package gloabaly. To not forget about such global package I add an echo script to mypackage.jsonwhich yells about this global package and I add this echo to all scripts 'yell && <script name>`. Now I can't forget to frequently search for non global alternatives.Additionally when installing a package locally I can reference it in
importorrequirestatements fairly easily. No construct required to check if the global package exists and matches the expected version or a version range. I see it often that in tutorials authors recommend installinggulpandwebpackglobally but then require either one or both packages in a local script. This can pay back badly when you upgradenodeornpmor any plugin you were told to install.PS: @sandeep I hacked this message on mobile :-)