Easiest way to detect Production or Dev environment in NextJs?

Yes, this should work out of the box if you access env via process.env.NODE_ENV.

When you run your application via next dev this will be development
While building your application and running next start sets this variable to production.

Therefore this should work:

const env = process.env.NODE_ENV
if(env == "development"){
  // do something
}
else if (env == "production"){
 // do something
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)