</>
Skip to content
Node.js lessons (12/44)

Node.js — package.json

Basic package.json

{
  "name": "my-app",
  "version": "1.0.0",
  "description": "My application",
  "main": "index.js",
  "scripts": {
    "start": "node index.js"
  }
}

Essential Fields

FieldDescription
namePackage name (lowercase, no spaces)
versionSemantic versioning (major.minor.patch)
descriptionPackage description
mainEntry point file
scriptsCommand shortcuts
authorAuthor information
licenseLicense type

Dependencies

{
  "dependencies": {
    "express": "^4.18.2",
    "lodash": "~4.17.0"
  },
  "devDependencies": {
    "nodemon": "^3.0.0",
    "jest": "^29.0.0"
  }
}

Version Ranges

SymbolMeaning
^Compatible with version
~Approximately version
*Any version
1.0.0Exact version

Scripts

{
  "scripts": {
    "start": "node index.js",
    "dev": "nodemon index.js",
    "test": "jest",
    "build": "webpack --mode production",
    "lint": "eslint ."
  }
}

Mini Practice

  1. Create a package.json
  2. Add dependencies
  3. Configure scripts
  4. Set version ranges

Up Next

Continue with File System — reading and writing files.

Related Topics

Frequently Asked Questions about package.json

What is package.json in Node.js?

package.json is a fundamental concept in Node.js. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn package.json?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn package.json.

Why is package.json important in Node.js?

package.json is essential for Node.js development. Understanding this concept will help you write better code and solve real-world problems more effectively.