npm install with --save does not save in package.json - node.js

I have npm-5.3.0 installed on my arch Linux.
I create a new project with npm init and fill in the details. This creates a package.json file with the details.
After that when I do npm install <package> --save, the file package.json does not change, and there is no entry for dependencies in the file. I had installed the package globally previously if that matters.

I found that the --save does not work with global and I had global=true set in the .npmrc file.
Setting global=false in the file fixed it.

Check update is available
npm i -g npm-check-updates
npm-check-updates -u
npm install
you have to change
"dependencies": {
"express": "",
"mongodb": "",
"underscore": "",
"rjs": "",
"jade": "",
"async": ""
}
then run
npm update --save

ı have solved adding npm 'FIRST' module from to dependencies manuelly in package.js this problem. Next, you can try npm install moduleName --save

Related

How to install npm package from command line with tilda~?

I want to install typescript in specific version and save the version to package.json:
"typescript": "~3.9.3"
Of course I can do it by write "typescript": "~3.9.3" in package.json and then run npm i.
But I want to install by cmd and then npm will update the package.json with the version I specified.
something like:
npm i typescript#~3.9.3 --save-dev
but its not work cause in the package.json npm write:
"typescript": "^3.9.7"
I want npm to write:
"typescript": "~3.9.3"
How can I achieve that with npm?

How to install #types from an NPM package that has # in it's name

I can install this node package
npm install #gamestdio/timer --save
However, when I try to install the types which go along with it
npm install #types/#gamestdio/timer --save
The result is
Invalid package name "#types/": name can only contain URL-friendly characters
You can use yarn
yarn add #types/#gamestdio/timer
or manually add to your package.json:
"dependencies": {
"#types/": "gamestdio/timer",
}
then remove your node_modules folder and run npm install again

npm install doesn't save dependency to package.json

It does add only when I execute: npm install <package_name> --save
In the documentation though: https://docs.npmjs.com/cli/install is written this:
By default, npm install will install all modules listed as dependencies in package.json.
Which is misleading.
npm install without arguments installs all dependencies (and dev dependencies) listed in the package.json file.
npm install --production installs all the dependencies (but no dev dependency)
npm install <package> installs a package and its dependencies.
npm install <package> --save installs a package and its dependencies, and adds it in the package.json file.
Edit: Since npm 5, --save is implied.
No, it's not. I think you are misreading the sentence.
npm install without any package name (as in your quote) will install all dependencies mentioned in the package.json.
Crete package.json file in your application folder.
Exp:- var/www/html/node/rest/package.json
{
"name": "node-api",
"main": "server.js",
"version": "0.0.1",
"dependencies": {
"express": "~4.0.0",
"mongoose": "~3.6.13",
"body-parser": "~1.0.1",
"mysql": "^2.5.4"
}
}
Then run npm install command your application folder
Exp:- var/www/html/node/rest npm install
You could run npm init again to update the dependencies info.

Node install npm modules

I'd like to install npm modules based on package.json
I'd like to know if there is anyway to automate installing modules.
For instance dependencies of package.json is as follows.
"dependencies": {
"express": "3.1.0",
"jade": "*",
"stylus": "*",
"mongodb": ">= 0.9.6-7"
}
do I have to install modules one by one like this?
npm install express#3.1.0
npm install mongodb#0.9.6
and etc.
Any help would be appreciate.
See the documentation about npm install.
By default, npm install will install all modules listed as dependencies in package.json.
So you can just type npm install.
when you are installing first time use --save, that module installation info will be added to package json
after that at new location you just need to run npm install
npm install express#3.1.0 --save
npm install mongodb#0.9.6 --save
npm install
also refer link
You can do this by typing:
sudo apt-get update
sudo apt-get install npm
use nvm to switch versions.
If you want to install a specific version of module you should use
npm install module_name#version --save
--save add's the module and the version of the module to your package.json file's dependencies. If you want to install just any version of a module you can use
npm install module_name --save
if you don't use --save at the and node would still install the last version of the module you want but it wouldn't add it to your package.json file . In this case you have some specific versions of some modules in your package.json file if you want to install them, you can simply use the
npm install
command. npm install installs all modules in your package.json file.
Also if you are new in nodeJs you can check this out. I hope this helps. Have a good day good sir.
You could install modules written in package.json as follows.
npm install

Will npm install global look in the local package.json?

Say I have "karma": "~0.12.0" in package.json, and the latest version of karma is 0.13.19. Will npm install -g karma look in the local package.json or will it install the latest version of karma available in npm?
Once you provide npm with a package name, it will not look for in the package.json file.
If you want specific version, you can provide it in the command, not in the package.json:
npm install -g karma#0.12.0

Resources