Non-tech founder’s guide to choosing the right software development partner Download Ebook
Home>Blog>Environment-variables-in-next-js

Environment variables in NEXT js

How to get env variables to your app code in NEXT.js application?

It’s not a big deal, but if you set ‘NODE_ENV’ for env in next.config.js it will not work correctly.

Anytime you will have ‘production’ (default value at build time) for any environments (staging, integration, production).

Just use another name instead ‘NODE_ENV’, for example ‘ENV’.


// next.config.js



require('dotenv').config()

module.exports = {

  env: {

    ENV: process.env.NODE_ENV,

  },

}

It will be available in your app code


export default () => <div>{process.env.ENV}</div>

Do you have an idea? Launch it with us!
By submitting this form, you agree with JetRockets’ Privacy Policy