I have some module in my node_module folder but because I am amateur in nodejs
, when I wanted to install theme, I forgot to use --save
with npm install
.now I have lots of module but my package.json
is empty so is there any way to add theme into package.json
.
Sorry if my question is silly one I am beginner in nodejs

- 2,322
- 7
- 28
- 58
4 Answers
Simply change into the directory containing node_modules
, backup any existing package.json
in there, then use npm init
to re-create the package.json
.
The generated package.json
will include any modules that already exist within node_modules
.
Sample run:
$ cd /my/project
$ mv package.json package.json.bak # Backup package.json
$ npm init # Recreate package.json with dependencies populated

- 2,121
- 2
- 15
- 16
-
"It only covers the most common items, and tries to guess sensible defaults." Hence, not all existing libraries in node_modules are added. – backslashN Nov 01 '17 at 08:00
Already asked and well answered!
Here're different ways suggested to create / maintain package.json
file
Is there a way to automatically build the package.json file for Node.js projects
Its simple. Edit the package.json file and add the following for development dependencies:
"devDependencies": {
"broccoli-asset-rev": "^2.0.2",
"broccoli-merge-trees": "^0.2.1",
"broccoli-svg-sprite": "^1.0.3",
......
}
To get a list of package names and version numbers, you may look at node_modules/module folder/package.json for each of the modules to pick up the official package name and version. It will be of the form:
{
"name": "<<name of the package>>",
"version": "2.1.0",
"description": "broccoli asset revisions (fingerprint)",
....
}
just copy the name and version information from above into devDependencies into your project's package.json and you should be good to go.
Also have a look here Is there a way to automatically build the package.json file for Node.js projects
-
Is the only way to add theme one by one I said I have lots module if I want to add theme one by it will take hours – Daniel.V Jul 26 '15 at 11:46
You can install the same package again using npm install --save <package>
and it should just replace the current package files with freshly installed ones. It will also add the packages you already added with the default version notation.

- 6,669
- 1
- 29
- 54
-
1I have already known this approach but I looking for way without installing my modules again – Daniel.V Jul 26 '15 at 11:48