Quick Steps Creating Node.js Project using npm

Step by step to create a new Node.js project using node package manager npm tool.

Step 1 - Creating new empty directory

For example we are going to create new directory named webapp via command line and then navigate to new directory.

D:\ToriCode\Nodejs>mkdir webapp

D:\ToriCode\Nodejs>cd webapp

D:\ToriCode\Nodejs\webapp>


Step 2 - Using npm tool to create new empty project

D:\ToriCode\Nodejs\webapp>npm init -y
Wrote to D:\ToriCode\Nodejs\webapp\package.json:

{
  "name": "webapp",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}
After the project create success the package.json file be created with content as below.
{
  "name": "webapp",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
}


Step 3 - Adding dependency to the new project

For example we add express package to new project by the npm command as below.

D:\ToriCode\Nodejs\webapp>npm install --save express
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN webapp@1.0.0 No description
npm WARN webapp@1.0.0 No repository field.

+ express@4.17.1
added 50 packages from 37 contributors and audited 126 packages in 3.091s
found 0 vulnerabilities

After adding package success the package.json file be updated to add dependencies.

{
  "name": "webapp",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.17.1"
  }
}

npm also download packge to node_modules directory.

Quick Steps Creating Node.js Project using npm