Home / Configs / Developer tools / package.json file

package.json generator: scripts, type and engines

Create a package.json with the right name, version, module type, scripts and Node version.

For Node.js 18 or newer with npm 9 or newer.

package.json describes your Node.js project: its name, how to start it, and which packages it needs. Fill in the basics to get a clean starting file, then add packages with npm install.

Create your config file

Type your own values. The file below updates as you type, and nothing you type leaves your browser.

Lowercase, no spaces. Letters, numbers, - . _
Three numbers, like 1.0.0
For example >=20

package.json
{
  "name": "my-app",
  "version": "1.0.0",
  "description": "My Node.js app",
  "main": "index.js",
  "type": "commonjs",
  "private": true,
  "scripts": {
    "start": "node index.js",
    "dev": "node --watch index.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "engines": {
    "node": ">=20"
  },
  "license": "MIT"
}

How this setup works

Diagram: package.json, then npm install, then npm start
package.json (describes the project) → npm install (adds packages) → npm start (runs your app)

Step-by-step setup

  1. Create a folder for your project and save the file above in it as package.json.
  2. Create the main file index.js with some code, such as console.log("Hello").
  3. Install a package: npm install express. This adds a dependencies section and a package-lock.json file.
  4. Run the app: npm start.
  5. Commit package.json and package-lock.json to Git. Do not commit node_modules.

What the important lines mean

Common errors and how to fix them

npm error code EJSONPARSE
package.json is not valid JSON, often a trailing comma or a missing quote. Paste it into a JSON checker to find the line.
npm warn config … Invalid name
The name has capital letters or spaces. Use lowercase letters, numbers and hyphens.
SyntaxError: Cannot use import statement outside a module
You used import but the type is commonjs. Set the module type to ES modules, or use require.
ReferenceError: require is not defined in ES module scope
The type is module, so require is not available. Use import, or switch to CommonJS.
npm error Missing script: "start"
Tick the start script above, or add it under "scripts".

Frequently asked questions

What does npm init do?
It asks you questions and writes a package.json. This generator gives you the same file without the questions.
Should I commit package-lock.json?
Yes. It locks the exact package versions so everyone, and your server, installs the same ones.
What is the difference between dependencies and devDependencies?
dependencies are needed to run the app. devDependencies are only for development, such as test tools. Add them with npm install --save-dev.

Written for: npm package.json format · Updated 2026-10-11

Fix a problem with this setup

More developer configs

See all 41 config generators