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>

Discover More Reads

Recent Projects

We take pride in creating applications that drive growth and evolution, from niche startups to international companies.

Let’s Build Something Great Together

Let’s discuss your project and see how Ruby on Rails can be your competitive advantage.

*By submitting this form, you agree with JetRockets’ Privacy Policy