Home » Nodejs » how to Add my node_module, modules into package.json

how to Add my node_module, modules into package.json

Posted by: admin November 29, 2017 Leave a comment

Questions:

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

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

Questions:
Answers:

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

Questions:
Answers:

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

and here: https://docs.npmjs.com/files/package.json

Questions:
Answers:

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.