Node.js Course
Node.js
/
Beginner

package.json

Definition

The heart of any Node.js project. It is a JSON file that holds metadata about the project, manages dependencies (libraries), and defines runnable scripts.

Explain Like I'm New

It's the recipe and instruction manual for your application. If you give your code to a friend, they don't have your downloaded libraries. They look at the `package.json` recipe, run `npm install`, and NPM automatically downloads all the exact ingredients needed to run your app.

Real World Example

Running `npm run dev`. Node looks in the `package.json` under the `"scripts"` object, finds the `"dev"` key, and executes the complex terminal command tied to it (like `nodemon src/index.js`).

Common Use Cases

  • •Dependency management
  • •Automating terminal tasks via scripts
  • •Publishing packages to NPM

Interactive Example

Loading...
Console output will appear here...

Interview Questions

basic

  • What command generates a new `package.json` file?

intermediate

  • What is the difference between `dependencies` and `devDependencies`?

advanced

  • What do the `^` (caret) and `~` (tilde) symbols mean in front of version numbers?

Flash Cards

Question

What command generates it?

Click to reveal answer
Answer

`npm init` (interactive) or `npm init -y` (skips questions and uses defaults).

Question

dependencies vs devDependencies?

Click to reveal answer
Answer

`dependencies` are libraries your app REQUIRES to run in production (like Express or Mongoose). `devDependencies` are tools only needed while coding (like Jest, TypeScript, or Nodemon). Production servers skip installing devDependencies to save space.

Question

What do ^ and ~ mean?

Click to reveal answer
Answer

Semantic Versioning. `^1.4.2` tells NPM: 'It is safe to auto-update to any 1.X.X version (minor updates), but NEVER 2.0.0 (breaking change)'. `~1.4.2` is stricter: 'Only update to 1.4.X (bug fixes only)'.