Node.js npm Setting up a package configuration


Node.js package configurations are contained in a file called package.json that you can find at the root of each project. You can setup a brand new configuration file by calling:

npm init

That will try to read the current working directory for Git repository information (if it exists) and environment variables to try and autocomplete some of the placeholder values for you. Otherwise, it will provide an input dialog for the basic options.

If you'd like to create a package.json with default values use:

npm init --yes
# or
npm init -y 

If you're creating a package.json for a project that you are not going to be publishing as an npm package (i.e. solely for the purpose of rounding up your dependencies), you can convey this intent in your package.json file:

  1. Optionally set the private property to true to prevent accidental publishing.
  2. Optionally set the license property to "UNLICENSED" to deny others the right to use your package.

To install a package and automatically save it to your package.json, use:

npm install --save <package>

The package and associated metadata (such as the package version) will appear in your dependencies. If you save if as a development dependency (using --save-dev), the package will instead appear in your devDependencies.

With this bare-bones package.json, you will encounter warning messages when installing or upgrading packages, telling you that you are missing a description and the repository field. While it is safe to ignore these messages, you can get rid of them by opening the package.json in any text editor and adding the following lines to the JSON object:

"description": "No description",
"repository": {
  "private": true