@nostjs/dotenv

DotENV even easier yet.

Usage no npm install needed!

<script type="module">
  import nostjsDotenv from 'https://cdn.skypack.dev/@nostjs/dotenv';
</script>

README

dotenv

DotENV even easier yet.

Installation

  1. Install the @nostjs/dotenv package on your project:
$ npm i --save @nostjs/dotenv
  1. Create a .env file:
$ touch .env

Usage

Add this line in the .env file:

MONGODB=mongodb://localhost:27017/users

Getting environment variables:

// TypeScript
import env from '@nostjs/dotenv';
const result = env.get('MONGODB');
console.log(result); // mongodb://localhost:27017/users
// Common JS
const env = require('@nostjs/dotenv');
const result = env.get('MONGODB');
console.log(result); // mongodb://localhost:27017/users

Getting environment variables (default values):

// TypeScript
import env from '@nostjs/dotenv';
const result = env.get('ENV', 'PRODUCTION');
console.log(result); // PRODUCTION
// Common JS
const env = require('@nostjs/dotenv');
const result = env.get('ENV', 'PRODUCTION');
console.log(result); // PRODUCTION

Getting environment variables (if there is no):

// TypeScript
import env from '@nostjs/dotenv';
const result = env.get('ENV'); // An error will be thrown
console.log(result);
// Common JS
const env = require('@nostjs/dotenv');
const result = env.get('ENV');  // An error will be thrown
console.log(result);