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, inMAJOR.MINOR.PATCHform.0.0.1means "very early". We cover this format in the Versions & the Lockfile chapter.type—"module"tells Node to use modernimport/exportsyntax for JavaScript files (the alternative is the olderrequire()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 devrunsastro dev;npm run buildrunsastro 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
$ npm init -y - Open your empty project folder in VS Code
- Open the terminal (
Ctrl+`) - 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.