Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

process.env.SOME_KEY is undefined

Tags:

node.js

How do I set the value of process.env.SOME_KEY=some value in the operating system and then read it in my node application? I am running on Windows.

I tried these steps:

SET SOME_KEY=abc 
npm start  

But when I try to read process.env.SOME_KEY, I am getting "undefined".

How do I set a env value and how do i read that in my code?

like image 325
BGeorge Avatar asked Feb 22 '18 16:02

BGeorge


1 Answers

Try this: https://www.npmjs.com/package/dotenv

All you need to do is add a .env with your environment variables, and require('dotenv').config() as soon as you can in your application (the script called by npm start would be a good place)

like image 199
Rick Avatar answered Oct 08 '22 00:10

Rick