Remix JS: Does Remix use process.env or import.meta.env?

Does Remix use vite’s import.meta.env or process.env?

The answer is, both. However it’s better to rely on vite’s import.meta.env because of 2 things:
1. Only VITE_ prefixed environment variables are imported
2. It’s also available in the non-SSR context, while process.env is a NODE thing only and not propagated to the browser.

So what does that mean?

You can have a
.env.development
and a
.env.production
file in the project root and add things like

and you can access those variables with e.g.

but this also gives you access to other variables, which are present by default

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.