Next.js Discord

Discord Forum

Share Environment variable between next app and express app

Unanswered
German Spitz posted this in #help-forum
Open in Discord
German SpitzOP
Hi, I have an express app and a next app dir app in the same repo. I have an environment varaible file which I would like to make accessible to both the express application and the next application.

How can I tell next about this environment variable file? It only needs to use the environment variable in a single middleware function.

For express the solution was to add this code to my index.ts file

dotenv.config({ path: path.resolve(__dirname, "../../.env") });

What is the solution for next?

1 Reply