Beginner Fundamentals
Understanding package.json
The package.json file is the heart of a Node.js project. It describes your project and lists its dependencies and scripts.
Common fields
// package.json (shown as an object)
{
"name": "my-app",
"version": "1.0.0",
"description": "A small Node.js project",
"main": "app.js",
"scripts": {},
"dependencies": {},
"devDependencies": {}
}
nameandversionidentify the project.mainpoints to the entry file.dependenciesare needed to run the app.devDependenciesare only needed while developing.
Scripts
The scripts field defines commands you can run with npm run:
{
"scripts": {
"start": "node app.js",
"test": "jest"
}
}
Run them with npm start or npm run test. The start and test names are special and can be run without run.
Summary
package.json keeps your project organized: metadata, dependencies, and handy scripts all in one file.