eris-env
v0.0.8
Published
Env
Readme
Eris Env Loader
About package
ErisEnvLoader is a simple package that aims to simplify the initialization of environment variables from .env files in Node.js projects.
Installation
npm i eris-envUsage
- Create a
.envfile in the root folder of your project and define your environment variables in the formatKEY=VALUE. For example:
DATABASE_DIALECT=postgres
DATABASE_HOST=localhost
DATABASE_PORT=5432- Create a
config.jsfile in the root folder of your project and define package.
// ES6
import { ErisEnvLoader } from 'eris-env';
// CommonJS
const ErisEnvLoader = require('eris-env');
const envLoader = new ErisEnvLoader();- Initialize variable:
const config = {
database: {
dialect: envLoader.getEnv('string', 'DATABASE', 'DIALECT'),
host: envLoader.getEnv('string', 'DATABASE', 'HOST'),
port: envLoader.getEnv('number', 'DATABASE', 'PORT'),
},
};