unjs / nitro

Next Generation Server Toolkit. Create web servers with everything you need and deploy them wherever you prefer.
https://nitro.unjs.io
MIT License
5.86k stars 492 forks source link

Support `.env` file for production / preview node preset #1492

Open pi0 opened 1 year ago

pi0 commented 1 year ago

It is quite often required to test production Node.js preset outputs with dotenv file. I am thinking of 3 possible ways:

Need to check how much is actual runtime overhead of dotenv (it seems as low as 5KB).

Also worth to node that, the "local" kind presets (Bun and Deno) both already have built-in dotenv support via CLI args. And there is an ongoing discussion within Node.js team to make it build-in feature..

Hebilicious commented 1 year ago

For cloudflare presets previews, there's builtin dotenv supports too, but the file needs to be named .dev.vars

pi0 commented 1 year ago

Good to know! My aim for this issue was mainly for Node presets but having other preset previews in mind, we might either leverage possible preview command or guide with args to use .env

gyhyfj commented 1 year ago

Currently, append --dotenv .env.local to dev or build script doesn't work like nuxt, is it?

danielroe commented 1 year ago

Note that this feature should be coming to Node natively in 20.6.

https://github.com/nodejs/node/pull/49185

gyhyfj commented 1 year ago

what if running in serverless environment rather than node server in future?

Hebilicious commented 1 year ago

Note that this feature should be coming to Node natively in 20.6.

nodejs/node#49185

Turns out the strong competition provided by deno and bun is working. We might have TS support in node at this rate 🤞🏽