Jonathan Allen Grant Jonathan Allen Grant - 1 year ago 157
JSON Question

How do I save all the dependencies I install through npm into my package.json file?

I ran

npm install
for a lot of packages, but I forgot to include the
argument. Now when I try to deploy on Heroku I get errors for missing certain dependencies. How can I automatically add those dependencies to my
file without doing
npm install --save
for each one?

Answer Source

You can add all installed packages not installed with --save to your package.json automatically by calling npm init. It will append the dependencies to your existing ones. No settings in your file should be lost. Still don't forget to make a backup of the file to be 100% secure!

If the dependencies have not been appended, it can happen that just the merging failed:

  1. Backup your existing package.json in order to keep the dependencies you have in your package.json already and all the other settings. We need this file later again.

  2. Delete the package.json and run npm init in order to create a new package.json including the modules installed without --save in dependencies.

  3. Merge the dependencies of your newly created package.json into your old one manually. Restore your merged package.json.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download