Access environment variables in custom server
See original GitHub issueFeature request
Is your feature request related to a problem? Please describe.
Environment variables are undefined
in a custom server. For example in server.js
...
const app = next({dev});
console.log(process.env.MY_ENV_VARIABLE);
...
In next.config.js
:
module.exports = {
env: {
MY_ENV_VARIABLE: 'hello',
},
};
Output:
undefined
Describe the solution you’d like
I would like to be able to use environment variable in a custom server.
Describe alternatives you’ve considered
No
Additional context
No
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:13 (3 by maintainers)
Top Results From Across the Web
Access environment variables in custom server - vercel/next.js
I would like to be able to use environment variable in a custom server. Describe alternatives you've considered. No. Additional context. No.
Read more >Basic Features: Environment Variables - Next.js
Learn to add and access environment variables in your Next.js application.
Read more >Making environment variables accessible to server-side ...
Amplify Hosting supports adding environment variables to your application's builds by setting them in the project's configuration in the Amplify console.
Read more >Working with Environment Variables in Node.js - Twilio
Environment variables are a great way to configure parts of your Node.js application. Learn how to work with them using helpful tools such ......
Read more >Setting up environment variables on HTTP Server - IBM
Set up environment variables for CGI programs running in an HTTP Server instance using the IBM ... Click the Custom Environment Variables tab...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
In case it’s helpful to future Google searchers, you can hook into the existing Next.js
.env.local
,.env
, etc. processing by including the following at the top of your custom server:I’m dealing with this same issue right now