Ondrej Tokar Ondrej Tokar - 5 months ago 8
Node.js Question

How can I add all dependencies from node_modules to package.json at once?

Normally I would execute:

npm install <package_name> --save
for each library/module.

However, is there a way to add all packages that are currently in the
node_modules
folder to the
package.json
dependencies?

Answer

You can do npm init to create package.json file with all dependencies currently installed, added into it by default. I have npm version 2.11.3.

Earlier versions of npm used to create a package.json file without the dependencies. If you are on such a version, run the below command to save the currently installed dependencies into it:

ls node_modules | xargs npm install --save

Of course, ls & xargs will work only if you are on Linux / Mac OS X.