dotenvjs
A runnable env environment
About
Gone are the days of using flat .env
files. This module will help you to build your env should you need that flexability.
Example
Here is a simple example:
const env = {
NODE_ENV: 'develop'
}
if (env.NODE_ENV === 'develop') {
env.LOGGING = true
}
module.exports = env
And you can now just use it as expected:
require('jsdotenv').config()
if (process.env.LOGGING) {
console.log('Look Mom no hands!')
}
Installation
You can simply install:
npm i --save jsdotenv
And then create a .env.js
file in your root. After that include this package like you see above and you are ready to go!
Additional Features
You can access this simple package with a simplified example, or use some of our additional Features.
parse
If you just wanna parse a file, try the following:
const jsdotenv = require('jsdotenv')
const parsed = jsdotenv.parse('/path/to/some/file.js')
console.log(parsed)
config
The example above is the minimalistic approach of the config
function. You can also use advanced features as well like so (defaults in parenthesis):
require('jsdotenv').config({
path: '.env.js'
})
License
MIT