Build HTTP APIs with routing, middleware, validation, controllers, and error handling.
Lessons
Load secrets and settings from environment variables.
Environment Config with dotenv is easiest to learn by reading the example, changing it, and observing the result.
// npm install dotenv
import 'dotenv/config';
const config = {
port: Number(process.env.PORT ?? 3000),
nodeEnv: process.env.NODE_ENV ?? 'development',
databaseUrl: process.env.DATABASE_URL
};
if (config.nodeEnv === 'production' && !config.databaseUrl) {
throw new Error('DATABASE_URL is required in production');
}
export default config;Practice the Environment Config with dotenv example in a small scratch file, then explain what changed and why.