I'm inside a folder
c:\nodeProject\node_modules\express>
Now, i want to update the module here, to the latest version.
I want NPM to check the package.json, and update this module.
What is the command line to do it?
npm uninstall express
npm install express#latest --save
That's what your looking for ?
Related
when the package.json file already exists and then install a new node module, how to add the new dependency data (module name and version number) to the package.json file?
I mean, not manually. Is there a native method using npm ?
As of npm 5.0.0 the dependancy should be automatically created on the file, prior to this version you must pass option --save when doing npm install to tell npm to write the package.json.
If you are adding any module as dependency module in you project, you can use this command npm install module_name --save it automatically add in package.json file
I'm using NPM and shrinkwrap (latest up to date version) to maintain my packages.
At the moment, one of my package current version is 1.1.0.
The latest version of this package is 2.2.0.
I want to update/upgrade this specific package to version 2.0.0 (and not the latest 2.2.0).
I thought that the procedure would be:
npm install in order to make sure that I'm synchronized with the npm-shrinkwrap
npm update myPackage#2.0.0
npm shrinkwrap
git add . && git commit -m "Updating package myPackage to version 2.0.0"
This doesn't seem to be the right road to go. It doesn't update the package.json and it always jump to the latest version. I have no control over this command to select the specific version I want.
I read the documentation about npm update and couldn't find the proper way to update the package to a specific version.
How to do this ? Would npm install --save myPackage#2.0.0 would be the correct procedure ? Then what will be the purpose of having npm update command ?
Solution:
npm install package#2.0.0 --save
npm update doesn't seem to interact with the shrinkwrap file as far as I can tell. But you can use npm install to set the version of a package.
This will update both package.json and npm-shrinkwrap.json:
npm install myPackage#2.0.0 --save
You can enter to package.jsonand write the version yourself on the dependencies. After that do npm install and it will install the correct version.
I have created the package.json using npm init. After some stage I installed few more modules as per the need.Rather than updating the package.json dependencies manually, is there any way to automatically update it??
If I understand what you are asking correctly, you want to use npm to install a dependency and have that dependency automatically added to your package.json ?
If so, use --save after the package name :
npm install [package name] --save
For download the all packages configured in the package.json, use:
npm update --save
Docs: https://docs.npmjs.com/cli/update
I understand the differences between npm install something and npm install something --save (for anyone wondering, the first one will install the dependency only while the latter will install the dependency and add it to your package.json).
However I do not understand why there is a --save option in the first place. In other words, why would you ever want to install a dependency without adding it to your package.json file? Why is the --save option not default?
A lot of websites/npm modules/SaaS suggest installing their module using npm install something (newrelic is one of them for instance), am I missing something?
Edit: Starting from NPM 5, --save is now on by default.
You would have a scenario such as you need some module to install without adding dependency to package.json file, for ex. you just want to try some module, and not sure you would be really using that module in production or while deploying, so instead adding the module dependency to package.json, just give it a try without using --save. this is why npm install without --save exists.
But For most of your modules you might require using --save, for ex. npm install express --save,
in this case you surely know that you are going to use express for you application.
The other scenario, for not using --save, would be, npm install heapdump or npm install nodemon, I would use it for testing my apps performance, but not add a dependency in the package.json :)
Also, As #surajck said in comment below: when you are doing global installs, in that case adding dependencies using --save, to the package.json would not make sense.
I just learned a nice trick from Jonathan Mills' JavaScript Best Practices course on Pluralsight. From the terminal:
npm config set save=true
Now I don't need to remember --save anymore. And I also now use
npm config set save-exact=true
Because I want the exact version of the package not the ^ prefix.
By default with version npm 5.0+ npm install adds the module to the dependencies list in the package.json file; with earlier versions of npm, you must specify the --save option explicitly. Then, afterwards, running npm install in the app directory will automatically install modules in the dependencies list.
I am using latest version of nodejs, 0.10.24
I followed this tutorial: http://net.tutsplus.com/tutorials/javascript-ajax/how-to-scrape-web-pages-with-node-js-and-jquery/
after installing npm install express, I can't find the package.json file in the same directory.
But when I tried this on Windows a few months before, I noticed that there was a file in the same directory.
Is there anything I need to do to fix?
Thanks,
When you npm install module ,the only goal is to download and save the module in ./node_module/ directory.
If you want get a package.json, you must use npm init and fill all the information asked.
After that, you can make npm install module --save, that command will download and add the module in your package.json.