Beginner Node.js Interview QuestionsBeginnerConcept
Node.js · Question 16
What is package.json in Node.js?
Direct answer
package.json is the manifest for a Node project — it declares name, version, entry point (main/module), scripts, dependencies, and metadata npm and tooling use to install, run, and publish the package.
Every Node app and publishable library has a package.json at the project root. npm reads it before creating node_modules; Node can resolve "type": "module" to decide ESM vs CommonJS (Q37).
| Field | Purpose |
|---|---|
| name / version | Package identity; semver for publishes |
| main | CommonJS entry (require) |
| module / exports | ESM entry and conditional exports |
| scripts | Named commands: npm run dev |
| dependencies | Runtime packages |
| devDependencies | Build/test tools only |
| engines | Supported Node/npm versions |
| type | "module" enables native ESM in .js files |
- private: true — prevents accidental npm publish of internal apps like @acedevhub/api.
- workspaces — monorepo array ["apps/*", "packages/*"] links local packages.
- Lockfile pair — package-lock.json pins exact tree; commit both together.
package.json
{
"name": "@acedevhub/api",
"version": "0.1.0",
"private": true,
"type": "module",
"scripts": {
"dev": "tsx watch src/index.ts",
"start": "node dist/index.js"
},
"engines": { "node": ">=20" },
"dependencies": { "fastify": "^5.0.0" }
}