Skip to content

Instantly share code, notes, and snippets.

@textbook
Last active April 9, 2022 15:29
Show Gist options
  • Save textbook/b304b63042110af535389e6b1068d592 to your computer and use it in GitHub Desktop.
Save textbook/b304b63042110af535389e6b1068d592 to your computer and use it in GitHub Desktop.
FOO=123
BAR=hello, world!
import "dotenv/config";
function main() {
const foo = process.env.FOO;
const bar = process.env.BAR;
if (!foo || !bar) {
throw new Error("missing FOO and/or BAR");
}
console.log("foo", foo, "bar", bar);
}
main();
{
"name": "dotenv-es6",
"version": "0.1.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"start": "node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "Jonathan Sharpe <[email protected]>",
"license": "ISC",
"dependencies": {
"dotenv": "^16.0.0"
}
}
$ node -v
v16.14.2
$ npm -v
8.5.0
$ npm start
> [email protected] start
> node index.js
foo 123 bar hello, world!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment