Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add dependency to package.json later

Tags:

node.js

In my application I have installed few node modules using below command

 npm install <modulename>

I forgot to mention "--save" to save the dependency list to package.json file.

Now I would like to update those dependencies in package.json file without updating the file manually . Any idea how it can be done ?

like image 384
refactor Avatar asked Mar 17 '16 10:03

refactor


People also ask

Can I modify package json?

json​ Of course, you can also simply edit the package. json file directly. Remember to run rush update afterwards to update the shrinkwrap file.

How update each dependency in package json to the latest version?

For updating a new and major version of the packages, you must install the npm-check-updates package globally. It will display the new dependencies in the current directory whereas running this command will list all the global packages which have new releases.


2 Answers

Just do: npm i name_of_package -S or the long version: npm install package_name --save

If you need to save it as a dev dependency, use the -D flag

like image 44
pixel 67 Avatar answered Oct 13 '22 00:10

pixel 67


You can run the same command again, specifying --save flag and it will be automatically included in package.json. The only problem is that the version of the package can be updated to newer version, so you may specify the specific version of your app: npm i --save [email protected].

Alternatively you can modify package.json yourself to include the dependency:

"dependencies": {
    "module": "*"
} 
like image 123
Vsevolod Goloviznin Avatar answered Oct 12 '22 22:10

Vsevolod Goloviznin