AceDevHub
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).

FieldPurpose
name / versionPackage identity; semver for publishes
mainCommonJS entry (require)
module / exportsESM entry and conditional exports
scriptsNamed commands: npm run dev
dependenciesRuntime packages
devDependenciesBuild/test tools only
enginesSupported 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" }
}