In .env files (NODE_ENV=development or production), in package.json scripts ("dev": "NODE_ENV=development nodemon src/server.js"), or in PM2 ecosystem files (env: { NODE_ENV: "production" }). Always set it many Express and npm packages behave differently based on NODE_ENV.
How do I set NODE_ENV?
More FAQs in Managing Multiple Environments in Node.js Development, Staging, and Production
Use separate .env files per environment (.env.development, .env.staging, .env.production), load the right one based on NODE_ENV with dotenv config path, centralize all config in a config module, and use environment-specific behavior for cookies, CORS, and logging. Always use different secrets per environment.
Development is for local coding (local DB, debug logging, dev secrets). Staging is for pre-production testing (staging DB, info logging, staging secrets, mirrors production). Production is the live app (production DB, warn logging, strong production secrets, real users).
Create a src/config/index.js module that loads dotenv, defines a config object with all variables (with defaults and type casting), validates required variables, and exports the config. Use config.isDev, config.isProd, config.isStaging for environment-specific behavior.
Still have questions?
Browse all our FAQs or reach out to our support team
Want to upskill yourself?
Your learning library
Small steps. Big possibilities.
Find your next course. Build something great.