process.env.NODE_ENV
Setting process.env.NODE_ENV
is a widespread convention to tell tools whether your app is being run in development or production.
It's crucial to respect the following convention, otherwise many tools will misbehave (such as React).
In development:
- Make sure
process.env.NODE_ENV
is one of these values:[undefined, 'development', 'dev', '']
. - If you use a server, make sure to add Vite's server middleware. (See API >
renderPage()
> Usage.)
In production (and staging):
- Make sure
process.env.NODE_ENV
is a value different than[undefined, 'development', 'dev', '']
.Note that:
- Upon starting your server in production, make sure to set
process.env.NODE_ENV
. (E.g.$ NODE_ENV='production' node server/index.js
.) - Upon building (
$ vite build
), Vite automatically setsprocess.env.NODE_ENV
to'production'
. - Upon manually triggering pre-rendering (
$ vike prerender
), Vike automatically setsprocess.env.NODE_ENV
to'production'
.
- Upon starting your server in production, make sure to set
- If you use a server, make sure you don't add Vite's server middleware: it isn't needed in production and would unnecessarily bloat your production server.
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?