Answer the question
In order to leave comments, you need to log in
When to use the global and local method of installing node.js modules?
I'm just starting to use grunt in my workflow and I have this question.
Project dependencies with grunt plugins can be applied in package.json in two ways.
1. By installing the plugin of interest globally and manually writing the dependency in package.json
2. By installing the plugin of interest locally, which will be automatically added to package.json
I think the first option is much easier, because I can completely create a stack of modules of interest to me globally and prescribe dependencies in each project myself rather than installing all (with a reservation) modules each time when creating a new project.
About the clause. In the blog of blog ( here) it is written that it is reasonable to install global modules when they need to be called from the console (correct if wrong).
So, when and under what conditions should modules be installed locally or globally?
Answer the question
In order to leave comments, you need to log in
Install plugins required for assembler tasks (grunt, gulp) locally, and add them to devDependencies (npm install [grunt-module] -D). This will allow you to create an isolated build environment for each project. Because the composition of the modules for the assembler may differ in different projects, so it will be easier for you to keep track of dependencies. In addition, if your project uses a version control system, then all development participants will be able to get the information necessary for building from the package.json of the project.
To prevent devDependencies modules from getting into production, it is enough to install the project packages on production by explicitly specifying the --save (-S) key.
It makes sense to globally install any general-purpose utilities, CSS preprocessors, translators (typescript), supervisors (forever, pm2, etc), in general, everything that needs to be called globally from the console. Accordingly, therefore, grunt / gulp itself is installed globally.
Install only command line utilities globally.
https://docs.npmjs.com/getting-started/installing-...
Honestly, lately I've been installing everything locally - it's easier for admins to deploy (it's enough for the script to cd $projectDir && npm install) and there will be no unexpected conflicts versions.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question