process.env.NODE_ENV
The NODE_ENV
environment variable (process.env.NODE_ENV
) is a widespread convention used by tools to distinguish between development and production environments.
In development, make sure process.env.NODE_ENV
is one of:
// In development:
process.env.NODE_ENV === 'development' // ✅
process.env.NODE_ENV === 'dev' // ✅
process.env.NODE_ENV === '' // ✅
process.env.NODE_ENV === undefined // ✅
In production, it should be any other value.
It's important to respect this convention: many tools run erroneously otherwise.
You can run
$ NODE_ENV='production' node server/index.js
to set a correctNODE_ENV
value for production.During build (
$ vike build
and$ vike prerender
), theprocess.env.NODE_ENV
value is automatically set to'production'
.
See also
- Node.js Docs - The difference between development and production
While the
process.env.NODE_ENV
convention was introduced by Node.js, it's used by tools regardless of whether you use Node.js. Thus, make sure to follow the convention even in non-Node.js environments. - Stack Overflow - What is NODE_ENV and how to use it in Express?
- [Warning] Wrong setup