package.json Explained

What is package.json?

package.json is your project's ID card and instruction sheet. It's a small text file (in JSON format) that lives in the root of your project and tells npm three key things: what the project is called, what commands it can run, and which packages it needs. When someone clones your project, this file is how npm knows what to download.

This site's actual package.json

Here's the real file that builds this website. Don't worry — we'll go through it line by line:

{
  "name": "siazly.com",
  "type": "module",
  "version": "0.0.1",
  "engines": { "node": ">=22.12.0" },
  "scripts": {
    "dev": "astro dev",
    "build": "astro build",
    "preview": "astro preview",
    "deploy": "astro build && wrangler pages deploy dist"
  },
  "dependencies": {
    "astro": "^6.4.2",
    "tailwindcss": "^4.3.0",
    "@tailwindcss/vite": "^4.3.0",
    "three": "^0.184.0"
  },
  "devDependencies": {
    "@astrojs/check": "^0.9.9",
    "typescript": "^6.0.3",
    "wrangler": "^4.97.0",
    "playwright": "^1.60.0"
  }
}

(A few packages are trimmed above for readability — the real file has the same shape.)

Field by field

  • name — the project's name. Lowercase, no spaces. For a private website like this it's just a label; for a published package it's the name people would install.
  • version — the project's own version number, in MAJOR.MINOR.PATCH form. 0.0.1 means "very early". We cover this format in the Versions & the Lockfile chapter.
  • type"module" tells Node to use modern import/export syntax for JavaScript files (the alternative is the older require() style).
  • engines — the Node version the project needs. "node": ">=22.12.0" means "Node 22.12 or newer". npm warns you if your version is too old.
  • scripts — named shortcuts for commands you run often. npm run dev runs astro dev; npm run build runs astro build. Whole chapter on this next.
  • dependencies — packages the project needs to build and run (here: Astro, Tailwind, Three.js).
  • devDependencies — tools you only need while developing, not for the site to function (here: the TypeScript checker, Wrangler for deploys, Playwright for tests).

Why two dependency lists? It separates "code my project actually uses" from "tools that help me build it". It's an important distinction with its own chapter: Dependencies vs devDependencies.

The "^" in front of versions

Notice every version starts with a caret, like ^6.4.2. That caret is a rule, not part of the number — it tells npm "this version or any compatible newer one is fine". You'll understand exactly what it allows in the versioning chapter; for now just know the symbol is intentional.

Creating your own package.json

Starting a brand-new project? npm init asks you a few questions and writes the file for you. Add -y to skip the questions and accept sensible defaults — handy when you just want to get going.

Start a new project's package.json

Terminal
$ npm init -y
In VS Code
  1. Open your empty project folder in VS Code
  2. Open the terminal (Ctrl+`)
  3. Run the command — a package.json appears in the file explorer, ready to edit

-y means 'yes to all defaults'. Drop it (npm init) if you'd rather answer the prompts yourself.

Edit it freely. Unlike node_modules and package-lock.json (both machine-managed), package.json is yours to edit by hand — just keep it valid JSON: double quotes around everything, and no comma after the last item.

Up next: turn that dependency list into a real node_modules folder with npm install.

FAQ

Frequently Asked Questions

What is package.json?
It's the manifest for your project — a small JSON file listing its name, version, the scripts you can run, and the exact packages it depends on. npm reads it to know what to install and run.
How do I create a package.json?
Run npm init and answer the prompts, or npm init -y to accept the defaults and generate one instantly. After that you edit it as your project grows.
What does "type": "module" mean?
It tells Node to treat your .js files as modern ES modules — so you use import/export instead of the older require(). This project sets it.
Is it safe to edit package.json by hand?
Yes — unlike node_modules and package-lock.json, package.json is meant to be edited. Just keep it valid JSON (double quotes, no trailing commas).