How to use environment variable in next js version 9.1.1. #16164
-
I am facing problem in creating environment variable in in nextjs 9.1.1. Thank you |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
I'd definitely recommend upgrading Next to 9.5.2! There are a TON of great new features! If that's not possible then this link to the old dotenv example should help with older versions of Next. You could create a
require('dotenv').config()
module.exports = {
env: {
// Reference a variable that was defined in the .env file and make it available at Build Time
TEST_VAR: process.env.TEST_VAR,
},
} |
Beta Was this translation helpful? Give feedback.
-
@jamesmosier i have upgraded my Next version to 9.5.2 as you said but its not working
this is how i am accessing it in pages
but its calling localhost not my backend url |
Beta Was this translation helpful? Give feedback.
-
Check this video out, It really helped me a lot. |
Beta Was this translation helpful? Give feedback.
I'd definitely recommend upgrading Next to 9.5.2! There are a TON of great new features!
If that's not possible then this link to the old dotenv example should help with older versions of Next.
You could create a
.env
file and then usedotenv
to import those variables:next.config.js