app.env
Reflects the current Node.js environment string (defaults to `NODE_ENV` or `"development"`).
Syntax
app.env Returns
string — The current environment name, e.g. `"development"`, `"production"`, or `"test"`.
Examples
import Koa from 'koa';
const app = new Koa();
app.use(async (ctx) => {
ctx.body = { env: app.env };
});
app.listen(3000);
Output
# NODE_ENV=production node server.js
{"env":"production"}
// Conditional behaviour based on env
if (app.env === 'development') {
const { koaDevLogger } = await import('./dev-logger.js');
app.use(koaDevLogger());
}
Output
(logger only active in development)
Notes
`app.env` is read-only in practice; set `NODE_ENV` in the shell before
starting your process. Koa uses it internally to decide whether to expose
stack traces in error responses (only in non-production environments).