Home > Net >  Node.js: How to read variables from the system?
Node.js: How to read variables from the system?

Time:12-11

I'm completely newbie with Docker and to make a deploy in production I need to read the "environment" variables instead of a file or instead of the package.json script line from the operating system of the container.

I know how to read variables from a .env file or from the script line but I don't know how to do it from the system and I don't know if its possible to read these variables from the system.

How can I do that? Is it possible?

CodePudding user response:

The process doesn't change. You still use the below to read environment variables that the process is running in. Reference for Node.

const envVariable = process.env.NAME_OF_VARIABLE;

Setting the variable in a Dockerfile can be done using the below. Docs for this are here.

ENV <key>=<value> ...

Things get more complicated when using things like LXC or Kubernetes though.

  • Related