Hsw
Hsw

Reputation: 37

How can I get environment variables of docker in node js?

I am using docker to run node server.js
In terminal, I execute docker run --env-file .env -p 8080:8080 -d node-web-app and I am trying to use process.env in server.js to get environment variables in docker
However, RangeError: Invalid status code: 0 occurs.
How can I fix it and get the environment variables in docker?
Thanks in advance.

Upvotes: 1

Views: 1073

Answers (1)

Jason Livesay
Jason Livesay

Reputation: 6377

That error is related to your HTTP handler, not env variables. Make sure you send a valid response.

 res.send('OK')
 res.send(JSON.stringify(process.env));


docker run -e "test=1" -e "testb=2"

Upvotes: 1

Related Questions