Load .env* files for external command #51239
ravinggenius
started this conversation in
Ideas
Replies: 1 comment
-
|
Is there any interest in this? It would be a huge quality of life improvement for any app that needs to run external (non-Next) commands with the environment variables fully resolved according to the rules Next uses. For instance:
I'm quite happy to write the CLI script and submit it as a merge request. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Goals
CLI command that populates the environment to execute a sub-command.
Non-Goals
I don't know. It seems pretty focused.
Background
I'm trying to reuse the environment processing/loading that Next uses to provide environment variables to other
npmscripts or other arbitrary commands. Specifically I have a database migration library (node-pg-migrate) that usesDATABASE_URL=....to connect to my database. I also have annpmscript formigrateset to runnode-pg-migrate. I guess what I'm looking for is a Next-awaredotenv"preload", so I can change mymigratescript to something likenext-env node-pg-migrateand have itexport DATABASE_URLtonode-pg-migrate. I thought@next/envwould have such functionality, but after glancing through the source, it doesn't seem to.Does anyone know how I can make this work? Currently I'm running
DATABASE_URL=... npm run migrate -- upfor local development. This isn't ideal because it pollutes my command history with my local database credentials and is a bit much to type every time I need to run a migration.I asked about this on the Discord server a while ago, but it didn't get any traction.
Proposal
Create a CLI wrapper script (
next-env) that uses@next/envto populate/export an environment for a given sub-command. ChangingNODE_ENVallows loading different environments.Beta Was this translation helpful? Give feedback.
All reactions