Skip to content

Instantly share code, notes, and snippets.

@jujhars13
Last active October 7, 2022 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jujhars13/6b7e95a71e5e70816f04ee090ce8e49b to your computer and use it in GitHub Desktop.
Save jujhars13/6b7e95a71e5e70816f04ee090ce8e49b to your computer and use it in GitHub Desktop.
MY_NAME=nitish
MY_NAME=sophie

Hacking dotenv

testing

npm i

ENV_FILE=.env.dev node test.js
ENV_FILE=.env.prod node test.js
{
"name": "nitish",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"dotenv": "^16.0.3"
}
}
require('dotenv').config({
path: process.env?.ENV_FILE ? process.env?.ENV_FILE : '.env.dev'
});
console.log (process.env?.MY_NAME);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment