Start Scripts
Define npm scripts so hosts and teammates know how to run your app.
Syntax
npm startHosting platforms run your app with npm start. Define that script (and a dev script for local work) in package.json.
start— production command, plainnode.dev— local command, using nodemon for reloads.
Also set the engines field so the host uses a compatible Node.js version.
Example
{
"scripts": {
"start": "node app.js",
"dev": "nodemon app.js"
},
"engines": {
"node": ">=18"
}
}When to use it
- A developer defines a start script in package.json so the ops team can launch the Express app with a standard npm start command.
- A CI/CD pipeline runs npm test before deploying to verify no tests are broken.
- A team uses npm run build to compile TypeScript and npm start to run the compiled output in production.
More examples
Common npm scripts
Defines the five most common lifecycle scripts for an Express project covering start, development, build, tests, and linting.
{
"scripts": {
"start": "node src/server.js",
"dev": "nodemon src/server.js",
"build": "tsc -p tsconfig.json",
"test": "jest --forceExit",
"lint": "eslint src/"
}
}Pre-start check script
Uses an npm prestart hook to validate environment config before the server starts, failing fast on missing variables.
{
"scripts": {
"prestart": "node -e \"require('./config')\"",
"start": "node server.js"
}
}Cross-platform env var in script
Uses cross-env to set NODE_ENV portably across Windows, macOS, and Linux without shell-specific syntax.
{
"scripts": {
"start:prod": "cross-env NODE_ENV=production node server.js",
"start:dev": "cross-env NODE_ENV=development nodemon server.js"
},
"devDependencies": {
"cross-env": "^7.0.3"
}
}
Discussion