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
| Field | Description |
|---|---|
| name | Package name (lowercase, no spaces) |
| version | Semantic versioning (major.minor.patch) |
| description | Package description |
| main | Entry point file |
| scripts | Command shortcuts |
| author | Author information |
| license | License type |
Dependencies
{
"dependencies": {
"express": "^4.18.2",
"lodash": "~4.17.0"
},
"devDependencies": {
"nodemon": "^3.0.0",
"jest": "^29.0.0"
}
}
Version Ranges
| Symbol | Meaning |
|---|---|
| ^ | Compatible with version |
| ~ | Approximately version |
| * | Any version |
| 1.0.0 | Exact version |
Scripts
{
"scripts": {
"start": "node index.js",
"dev": "nodemon index.js",
"test": "jest",
"build": "webpack --mode production",
"lint": "eslint ."
}
}
Mini Practice
- Create a package.json
- Add dependencies
- Configure scripts
- 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.