What is package.json and how to create one

· Category: Node.js

Short answer

package.json is a manifest file that contains metadata about your Node.js project, including its name, version, dependencies, and scripts. Create one by running npm init or npm init -y.

How it works

The file serves as the central configuration for npm and Node.js tools. It lists all external packages your project needs under dependencies and devDependencies. The scripts field defines command shortcuts you can run with npm run. The main field specifies the entry point of your application.

Example

{
  "name": "my-app",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "start": "node index.js"
  },
  "dependencies": {
    "express": "^4.18.0"
  }
}

Why it matters

Without package.json, collaborators cannot install the correct dependencies, and deployment pipelines lack the information needed to build and run your application. It also enables semantic versioning control through the engines field.