Node.js › Cloud & DevOps
What is a twelve-factor app, and how does it guide how a Node.js application should be configured for cloud deployment?
IntermediateAnswer
The twelve-factor methodology is a set of best practices for cloud-native apps: storing configuration in environment variables (so the same build deploys unchanged across environments), treating backing services as attached resources via a URL, keeping the app stateless so any instance can handle any request, and logging to stdout rather than managing log files directly.
const config = {
port: process.env.PORT || 3000,
databaseUrl: process.env.DATABASE_URL,
};
console.log(JSON.stringify({ level: 'info', message: 'Server started' }));Real-world example A twelve-factor Node.js API deploys unchanged to a laptop, staging, and production simply by supplying different environment variables, without separate config files or code branches per environment.