- install it
npm i requirenv
- add a file
.env.required.js
to the root of your project - prepend
requirenv &&
to the scripts that do you want to fail early if any required environmental variable is missing - that's it
module.exports = [
"foo",
"bar",
"baz",
]
{
...
"scripts": {
"dev": "requirenv .env.local && next dev",
"build": "requirenv && next build",
"start": "requirenv && next start"
},
....
}
const missing = require('requirenv')
that's it. Missing is an array with all the missing variables. remember to call this after dotenv, if you use it.