Ondrej Tokar
Ondrej Tokar

Reputation: 5080

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?

Upvotes: 3

Views: 3800

Answers (3)

Taran J
Taran J

Reputation: 805

Use : npm init

ref: https://docs.npmjs.com/cli/init

it basically asks you a set of questions and writes out a package.json for you.

Upvotes: 3

rkrishnan
rkrishnan

Reputation: 806

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.

Upvotes: 6

MatejMecka
MatejMecka

Reputation: 1486

The package.json file is used by NPM to learn about your node.js project.

Use npm init to generate package.json files for you!

It comes bundled with NPM. Read its documentation here: https://docs.npmjs.com/cli/init

Also, there is a standalone tool if you're so inclined (it's made by the maker of npm): https://github.com/isaacs/init-package-json

Upvotes: 1

Related Questions