1.0.0 • Published 6 years ago
not-dotenv v1.0.0
Remake of dotenv that loads Environment Variables from JS or JSON files (by default .env.js or .env.json)
Install
$ npm i not-dotenvUse
Create a .env.js or .env.json file in the root directory of your project (by default .env.js will be loaded in case both are present)
module.exports = {
HELLO: 'WORLD from .env.js'
}Or
{
"HELLO": "WORLD from .env.json"
}Require not-dotenv and invoke .config(), then use the environment variables loaded in process.env
require('not-dotenv').config()
console.log(process.env.HELLO)
// WORLD from .env.js- In case you want to load environment variables from a specific location, set the
pathproperty in the optional configuration settings
require('not-dotenv').config({ path: './.env.json' })
console.log(process.env.HELLO)
// WORLD from .env.json- You can also get the environment variables loaded in the returned object through its
parsedproperty
const result = require('not-dotenv').config()
console.log(result.parsed.HELLO)
// WORLD from .env.js- Or check the error in case it happens during the loading process
const result = require('not-dotenv').config({ path: 'wrong path' })
console.log(result.error)
// ERROR ...1.0.0
6 years ago