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 sets process.env.NODE_ENV to 'production'.
    • Upon manually triggering pre-rendering ($ vike prerender), Vike automatically sets process.env.NODE_ENV to 'production'.
  • 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