//In CMD
npm i dotenv
//in JS file
require('dotenv').config();
require('dotenv').config();
console.log(process.env.MY_ENV_VAR);
// Terminal/CMD
npm i dotenv
//In .env file
SPECIAL_KEY = 0000000 //whatever the key
//In nodejs file - 2 point usage
//1 - initialisation
require('dotenv').config();
//2 - using the special key
const specialKey = process.env.SPECIAL_KEY
console.log(specialKey);
const config = require('dotenv-config')();
console.log(config.test); // localhost
module.exports = config;
import * as dotenv from 'dotenv' // see https://github.com/motdotla/dotenv#how-do-i-use-dotenv-with-import
dotenv.config()
import express from 'express'
This is used to add a specific path to locate the .env file if we use like this
.config() then this is finding .env file in our cwd - current working directory.
require('dotenv').config({ path: '/custom/path/to/.env' })
this module is used to access environment variable in our application
import * as dotenv from 'dotenv' // see https://github.com/motdotla/dotenv#how-do-i-use-dotenv-with-import
dotenv.config()
import express from 'express'