How to sync the dependency of package json in npm - node.js

In my case,i use npm install moduleName -save to install a module ,but after npm notice that it is install complete,the package.json will not be add dependencies of the module;
Is there any solution to sync from module to dependencies;
Thanks at first

You need npm install moduleName --save (2 '-')

Actually you can use one -s. Here is the quote from the npm documentation:
As of version 2.0.0 you can provide a path to a local directory that
contains a package. Local paths can be saved using npm install -S or
npm install --save, using any of these forms:
So if you wanted to install lodash you could use:
npm install lodash --save
or:
npm install -S lodash

Related

How can I uninstall npm version [duplicate]

This question already has answers here:
Message "npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead"
(23 answers)
Closed 3 months ago.
My npm version is 8.11.0.
When I create react package, but it gives me a Warn.
How can I uninstall it?
npm uninstall <package_name>
To uninstall an unscoped, global package on the command line, use the uninstall command with the -g flag:
npm uninstall -g <package_name>
Locally uninstall npm package:
To uninstall a package you have previously installed locally, run following from the project root folder (the folder that contains the node_modules folder):
npm uninstall <package-name>
Note: This operation will also remove the reference in the package.json file.
If the package was a development dependency, listed in the devDependencies of the package.json file, you must use the -D / --save-dev flag to remove it from the file:
npm uninstall -D <package-name>
Globally uninstall npm package:
If the package is installed globally, you need to add the -g / --global flag:
npm uninstall -g <package-name>
You need to just write in your terminal
npm uninstall <package_name_which_you_want_to_uninstall>

npm init automatically create etc directory and `--save-dev` doesn't work

When I use npm init in cmd, npm creates an etc directory and package.json.
Then when I use npm install stylus --save-dev,the module is downloaded in node_modules directory. But I can not find dependency in package.json
and I realize I can use command ls, mkdir in cmd, which is also confusing.
after npm init I cat package.json
This is my initial directory after I use npm init, I get etc\ directory, which should not be in this directory
This is the directory after I use npm install stylus --save-dev
After installing stylus, I cat package.json, but no dependency in this file
I cannot find out what is wrong.
I'm using Windows 10
node-version 8.9.1
npm version 5.5.1
npx installed
You could try:
npm install -D stylus
or
npm install stylus -D
For multiple packages, do this:
npm install pkg1 pkg2 pkg3 -S
or
npm install -S pkg1 pkg2 pkg3
The difference between -S and -D is -S adds the package(s) to dependencies while -D adds to dev-dependencies.
-S and -D are flags, regardless of where you put it, be it before the package names or after the package names, npm will recognise them and act accordingly.
Check out this command
npm install --save-dev stylus
When you write stylus then --save-dev it is identifying --save-dev as package not as command.
For multiple package to install we write
npm install package1 package2 package3
I was also having the same problem. I assume that you would have set "prefix" key for npm local configuration. Running:
npm config delete prefix
may help. Then start your project:
npm init or npm init -y

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

How to npm install a module without installing peer dependencies

I am trying to npm install karma-jasmine and for some odd purpose only want to npm install that module and not karma. It install karma as well as it is defined as a peerDependency. Is it possible to not install peerDependency and how? I am using npm 1.4.28
This is my package.json
{"dependencies": {"karma-jasmine": "0.2.3"}}
Can you update to newer npm, let say version >=3 ? It does not install peerDependencies by default.

How to install a previous exact version of a NPM package?

I used nvm to download node v0.4.10 and installed npm to work with that version of node.
I am trying to install express using
npm install express -g
and I get an error that express requires node version >= 0.5.0.
Well, this is odd, since I am following the directions for a node+express+mongodb tutorial here that used node v0.4.10, so I am assuming express is/was available to node v0.4.10. If my assumption is correct, how do I tell npm to fetch a version that would work with my setup?
If you have to install an older version of a package, just specify it
npm install <package>#<version>
For example: npm install express#3.0.0
You can also add the --save flag to that command to add it to your package.json dependencies, or --save --save-exact flags if you want that exact version specified in your package.json dependencies.
The install command is documented here: https://docs.npmjs.com/cli/install
If you're not sure what versions of a package are available, you can use:
npm view <package> versions
And npm view can be used for viewing other things about a package too. https://docs.npmjs.com/cli/view
It's quite easy. Just write this, for example:
npm install -g npm#4.6.1
Or:
npm install -g npm#latest // For the last stable version
npm install -g npm#next // For the most recent release
First remove old version, then run literally the following:
npm install express#3.X
or
npm install express#4.X
and for stable or recent
npm install -g npm#latest // For the last stable version
npm install -g npm#next // For the most recent release
In my opinion that is easiest and fastest way:
$ npm -v
4.2.0
$ npm install -g npm#latest-3
...
$ npm -v
3.10.10
you can update your npm package by using this command:
npm install <package_name>#<version_number>
example:
npm install yargs#12.0.2
You can use the following command to install a previous version of an npm package:
npm install packagename#version
I have a general way to solve this type of problems, which could be helpful too, especially when cloning repositories to run them locally, but requires a little more analysis of the versions.
With the package npm-check-updates I verify the versions of the packages (according to the package.json file) that are not declared in their latest available versions, as shown in the figure (https://www.npmjs.com/package/npm-check-updates):
With this information we can verify the update status of the different packages and make decisions as to which packages to upgrade / degrade and which ones do not.
Assuming that we decided to update all the packages as they are listed, we can use the ncu -u command which only modifies your package.json file. Run npm install to update your installed packages and package-lock.json.
Then, depending on the requirements of the repository, we can refine what is needed, installing the specific versions with
npm view <package> versions and npm install <package>#<version>
The easiest way I found: add package name with the version in package.json and then run npm install
"next-seo": "^5.4.0",
"next-themes": "^0.1.1",
"nextjs-progressbar": "^0.0.14",
If you have to install an older version of a package, just specify it
npm install #
For example: npm install express#3.0.0
You can also add the --save flag to that command to add it to your package.json dependencies, or --save --save-exact flags if you want that exact version specified in your package.json dependencies.
The install command is documented here: https://docs.npmjs.com/cli/install
If you're not sure what versions of a package are available, you can use:
npm view versions
And npm view can be used for viewing other things about a package too. https://docs.npmjs.com/cli/view
Use npm config set save-exact=true if you want to install the exact version

Resources