NPM Workflow for global modules - node.js

I want to globally install dev dependencies like mocha and babel and a few other things as well. So, I also need to reference to the global modules in the project package.json file.
My idea is to npm init the "npm" directory where the global "node_modules" are and then to install the global modules from there using npm install --save so that they are installed globally and the "global" package.json file is udated. Then, when I want to use one of these modules in a project, I just copy the line from the "global" package.json and paste it into the devDependencies of the project package.json.
My problem is that this was working fine but lately the "global" package.json file is not being updated when I install --save.
Why would this stop working?
I'm using Windows 10 and npm v3.8.6

Related

Dependencies aren't added to package.json file

I am building a MEAN stack application using vscode editor. I installed some packages with npm, but package.json doesn't add them my project configuration.
you probably forgot to add the --save flag to your npm install
npm install PACKAGE_NAME --save
will add it to the dependencies in your package.json. If you use --save-dev, it will add them to dev dependencies instead

How to install all relevant packages?

I have a Node.js project which has several dependencies.
I created the package.json file (npm init)
and try to install all the relevant packages
(npm install all) or (npm install)
with npm install I'm getting the following result:
npm notice created a lockfile as package-lock.json. You should commit this file.
but
when I'm trying to run, I'm getting error that a package is missing (i.e express and I need to install it manually)
Is there a way (command) to install at once (with one command) all the relevant packages and dependencies ? (instead of install each of the package manually) ?
Update 1:
I think I found the solution to your problem, you can use this npm module for auto installing your dependencies.
Install
npm install -g auto-install
Usage
Run auto-install in the directory you are working in.
So npm is simple!
you can add a single package using npm install package-name
or
you can install all using npm install, this will read your package.json file and install all the packages which are in there
Additionally you can do this:
npm install package1 package2 package to install multiple packages.
If a required dependency is not installed, just install it once manually using npm's --save argument and it will automatically add that dependency to your package.json.
For instance, if you are missing the express dependency, just run:
npm install --save express
That will install the dependency in your node_modules folder and also automatically update your package.json file to include express. On subsequent installs on different machines, you'll now only need to run npm install and the express package will be added automatically.
Update with a little more context: In Node your package.json file defines all dependencies that are required for your project. However, these dependencies are not automatically generated for you. npm init will create a boilerplate package.json, but it will not fill that package.json with any dependencies.
You need to define the dependencies yourself, which you can do one of two ways:
Manually add lines to your package.json's dependencies section
Use npm install --save <package name> to have npm install a package and automatically save that package as a dependency in your package.json file
If you aren't familiar with package.json files, I'd recommend sticking to approach number 2 so that npm handles editing that file for you.
Once you have a package.json with all of the dependencies you need, then when you pull down your project onto new machines you will be able to automatically install all dependencies at once using a simple npm install command. You can test this on your own machine by deleting the node_modules folder and running npm install, then trying to run your project. If it runs fine then you successfully added all dependencies to your package.json. If it complains about a missing package then add that package with npm install --save <package>

npm install --save not installing the module

I am integrating firebase cloud functions with my app's workflow. I needed to install a package so I did npm install --save #sendgrid/mail. The installation was a success but I can't see the dependency either in node_modules folder or the package.json file. What do I do?
One way to add the package would be to do the reverse. Add #sendgrid/mail to your package.json with the version you want, and then run npm install.

when npm install or not install devDependencies?

I using npm a few years. But I still don't know when npm install devDependencie and when don't install?
In npm docs, npm install --production don't install devDependencies.
But in my testing, I init a package, add eslint to dependencies, run npm install --production, the eslint's devDependencies still installed? I don't know why?
I want a table to specify when to install or when to skip.
devDependencies are dependencies that you only use during local development, including running local tests and running local build tools. eslint is a devDependency because you only use it for local code linting.
dependencies are for dependencies required for your final deliverable project to run. Your project might be an npm module, or a node program, or a bundled Javascript file. If you use Webpack to build your Javascript, but don't include Webpack's source code in your final output, then webpack is a devDependency.
This is especially important when publishing an npm node module so that the consumers of your package don't download other packages that are never used.

What's the difference between depenencies and devDependencies with NPM 5

The below question refers to a project I'm not publishing to npm.
In NPM 3, if I had a package in devDependencies and ran shrinkwrap (without --development) then npm-shrinkwrap.json would not include the packages in devDependencies.
But with NPM 5, packages in dependencies and devDependencies are added to package-lock.json, with those from devDependencies having "dev": true.
So, if I'm just using npm install x to add packages and npm install to install everything on, say, a build server, is a package listed in dependencies treated any differently from a package listed in devDependencies?
It will make sense on production. When you'll need to install all packages, except dev.
npm i --production
From npmjs.org:
With the --production flag (or when the NODE_ENV environment variable is set to production), npm will not install modules listed in devDependencies.

Resources