liveBook · Manning

Package.json

As explained in Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform

package.json is a JSON-formatted project manifest that declares package metadata, dependencies, and related configuration for a Node.js project.

A Node.js project uses package.json to record project metadata, dependencies, and npm scripts. Create one in a new project directory with `npm init -y`; the `-y` option accepts default field values that you can edit later. section 2.6.1

As the project grows, update the manifest for the job at hand:

  • Install an application dependency with `npm install express`. npm records it under `dependencies` and installs package code under `node_modules`. The older `--save` flag is no longer needed for this behavior. section 2.6.2
  • Add `"start": "node src/index.js"` under `scripts` to launch the service with `npm start`. This gives callers a standard command without requiring them to know the entry-point path. section 2.6.7
  • Add nodemon under `devDependencies` and a `start:dev` script for live reloading. Run that custom script with `npm run start:dev`; install only production dependencies with `npm install --omit=dev` when development tools are unnecessary. section 2.6.8 section 2.6.7
Listing 2.7 Adding a start script for development
{
  "name": "example-3",
  "version": "1.0.0",
  "description": "",
  "main": "src/index.js",
  "scripts": {
    "start": "node src/index.js",         #1
    "start:dev": "nodemon src/index.js"   #2
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^5.0.0-beta.1"
  },
  "devDependencies": {                    #3
    "nodemon": "^2.0.18"                  #4
  } 
}

The working manifest places Express in `dependencies`, nodemon in `devDependencies`, and separate launch commands in `scripts`. section 2.6.8

Scripts can also provide a consistent test command: a `test` script runs Playwright through `npm test`. If the entry point moves into `src`, update its location in package.json rather than leaving the manifest pointing at the old path. section 9.8.6 section 2.6.3

How Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform covers it

How deep it goes
Works through initialization, dependency fields, and runnable scripts, without detailing npm’s manifest resolution internals.
Examples
Shows generated defaults, Express and nodemon entries, separate start scripts, and a Playwright test script.
What it assumes
Assumes basic terminal and Node.js familiarity while teaching project initialization with `npm init -y`.
What you can do after
Operate/configure it to install dependencies and run a microservice through development, production, and test commands.
How it connects
Connects npm scripts, Node.js entry points, application dependencies, development dependencies, live reloading, and automated testing.

Also explained in

Compare how 5 books explain package.json →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform. The section links point to the parts of the book it draws on.