Building Your Learning Module...
Getting things ready for you!
Find videos you like?
Save to resource drawer for future reference!
package.json is a configuration file that contains metadata about your project. It lists dependencies, defines scripts, specifies versions, and much more. Every Node.js project has one!
Lists all required packages
Define custom commands
Project info and configuration
{
"name": "my-awesome-project",
"version": "1.0.0",
"description": "A brief description of your project",
"main": "index.js",
"scripts": {
"start": "node index.js",
"test": "jest"
},
"keywords": ["javascript", "node", "web"],
"author": "Your Name <you@example.com>",
"license": "MIT",
"dependencies": {
"express": "^4.18.2",
"react": "^18.2.0"
},
"devDependencies": {
"jest": "^29.5.0",
"webpack": "^5.88.0"
}
}Unique identifier for your package. Lowercase, no spaces.
"name": "my-package"Semantic versioning (MAJOR.MINOR.PATCH). Example: 1.2.3
"version": "1.0.0"Entry point of your application. File that runs when package is imported.
"main": "index.js"Custom commands you can run with npm run or yarn.
"scripts": { "start": "node app.js" }Packages needed for your app to run in production
expressWeb server
reactUI library
axiosHTTP client
Tools only needed for development and testing
webpackBundler
jestTesting framework
eslintLinter
^Allow minor and patch updates
^1.2.3 → allows 1.2.4, 1.3.0 but NOT 2.0.0~Allow only patch updates
~1.2.3 → allows 1.2.4, 1.2.5 but NOT 1.3.0*Accept any version (not recommended!)
* → latest version alwaysexactNo symbol = exact version only
1.2.3 → only 1.2.3, nothing else{
"scripts": {
// Development
"dev": "webpack serve --mode development",
"start": "node server.js",
// Building
"build": "webpack --mode production",
"build:watch": "webpack --watch",
// Testing
"test": "jest",
"test:watch": "jest --watch",
"test:coverage": "jest --coverage",
// Linting & Formatting
"lint": "eslint src/",
"lint:fix": "eslint src/ --fix",
"format": "prettier --write 'src/**/*.js'",
// Utilities
"clean": "rm -rf dist/",
"prebuild": "npm run clean", // Runs before build
"postbuild": "npm run deploy", // Runs after build
// Multiple commands
"validate": "npm run lint && npm run test"
}
}
// Run with:
npm run dev
npm run build
npm test // "test" doesn't need "run"package.json is the heart of your project
Contains all metadata
Production vs development
Choose the right category
Automate tasks easily
npm run script-name
^ for minor updates
~ for patch updates only