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
}