Package.json practical side clarified

Intro

As for beginning of this article let me cite the most important [docs.npmjs.com] :

A package.json file must contain "name" and "version" fields :

  • The "name" field contains your package's name, and must be lowercase and one word, and may contain hyphens and underscores ;
  • The "version" field must be in the form x.x.x and follow the (semantic versioning).
    semantic versioning

Package.json – main

Consider the following information within you package.json :

{
"name": "abc",
"main": "lib/some-entry-file.js",
...
}

The require('abc') actually will do require lib/some-entry-file.js . Consider this requirement as some kind of alias for the entry point .

All credits to prosti [stack overflow]


Property of "main": "some-entry-point" is also useful when you have long path to the entry file , for an example :

{
"name": "abc",
"main": "./some-long-path/src/server/some-entry-file.js",
...
}

Using with nodemon you would only need to use (dot) that denotes pwd i.e. root of your working directory , consider the following to conclude what I've just said above :

{
"name": "abc",
"main": "./some-long-path/src/server/some-entry-file.js",
"scripts": {
    "start" : "node ."
  },
...
}

Now all you have to do is just run the following command of npm start

Either it would be node or nodemon or any other relevant and it's followed by dot (.) which denotes any path as a value assigned to "main" in package.json will always find so called entry-point to run things right without any error of ENOENT or similar thrown .

All credits to Aakash [stack overflow]


Deps saving demystified

Deps stands for dependencies, where as..:

  • Dev – development
  • Prod – production
Full command (a.k.a. --option)Shorthand (a.k.a. -flag)Action
--save-prod-Psave deps for prod
--save [^default]-Sshorter version of -P
--save-dev-Dsave deps for dev . not prod

^NOTE : Since NPM v5.0.0 and higher --save (-S) as alias of --save-prod (-P) are by default, so no need explicitly to define whilst installing packages

All credits to voithos [stack overflow]

Useful way to get reference out-of-the-box is to run one (or both) of the following commands :

npm --help
npm command_name -h


Useful references