How to use npm scripts in package.json — Basic
Standard scripts to start the server, run migrations, and seed the database.
Learn: npm scripts are the team’s shared commands—everyone runs the same start and migrate steps. Document them in README so onboarding takes minutes, not hours.
Supplementary examples
Run migrations before start in dev
# package.json
"scripts": {
"dev:reset": "knex migrate:rollback --all && knex migrate:latest && knex seed:run && nodemon src/server.js"
}Course example
{
"scripts": {
"start": "node src/server.js",
"dev": "nodemon src/server.js",
"migrate": "knex migrate:latest",
"seed": "knex seed:run"
}
}
Additional references & examples
- npm scripts
Define start, test, and custom commands in package.json.
- Node.js documentation
Official Node APIs: modules, events, and runtime behavior.