package.json in NPM

  • package.json file is created after performing npm init
  • package.json file contains the npm configuration for that project

Sample : package.json file

{
  "name": "demo",
  "version": "1.0.0",
  "description": "Demo of 3rd Part demo packages",
  "main": "index.js",
  "scripts": {
    "start": "node index.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Tyson Gill",
  "license": "ISC"
}
  • main specifies the entry point of the node application.
  • start in above script points the entry point of the npm project, where it states that if start command is fired for this npm project what to do, in our case we execute command “node index.js”. It is typially a bash script, you can add any command in this place. We can execute it using command “npm run start”
  • test is a second life cycle script of npm just like start, its purpose is it execute text scripts

Leave a Comment