package.json Basics

View saved

Create package.json

In an empty project folder:

npm init -y

Key fields

  • name and version identify the package
  • main or exports point to the entry file for libraries
  • scripts define shortcuts like start and test
  • dependencies lists packages your app needs to run

Mark the module type

For ES modules in .js files:

{
  "name": "my-app",
  "version": "1.0.0",
  "type": "module",
  "scripts": {
    "start": "node app.js"
  }
}

Commit the lockfile

After installing packages, commit package-lock.json so installs stay reproducible.

Comments

One comment per signed-in account. Comments are saved with this page’s URL.