I have config server which is a containerized. now my task to create a API in express. the problem i am facing is how to read the common properties defined in the config server in my express api.
Asked
Active
Viewed 11 times
1 Answers
0
Create a .env File to store your environment variables. Example: .env.development or .env.test or .env.production files that you can put into a config folder.
Download the node module "node-foreman" https://github.com/strongloop/node-foreman
Now run your web server using foreman and specify which environment you want with the following command line command.
./node_modules/foreman/nf.js --env ./config/.env.development start web=1
That will load the correct environment that you want.
Then to access your environment variables in the actual code, you use "process.env".
For example if you have a key-value pair in your .env file like version=5.5 then to access it in the code you do process.env.version.

Hackbyrd
- 436
- 5
- 12