DittoEnv
DittoEnv is a simple Node.js library for managing environment variables in your application. It reads variables from a .env file and provides easy-to-use methods for accessing them.
Features
- Reads a
.env
file from the current working directory - Provides
get
andgetOr
methods for easy access to environment variables - Falls back to
process.env
if a key is not found in the .env file
Installation
npm install dittoenv
Usage
- Import the Library
import DittoEnv from 'dittoenv';
- Create an instance
const env = new DittoEnv();
Use the get method to retrieve the value of an environment variable:
const port = env.get('PORT');
The get method will throw an error if the requested key is not found in the .env file or process.env.
Use the getOr method to retrieve the value of an environment variable or return an alternate value if the key is not found:
const port = env.getOr('PORT', 3000);
License
This project is licensed under the MIT License.