How to read Environment variables on virtual host in Nodejs app?

#1
Hello everyone, how can I read an environment variable, (Virtual Host - External App) in a NodeJS application?

I have tried process.env.TESTVAR but it is undefined

Thank you!
 
#3
Hi Cold-Egg, yes I configured the App with nodejs correctly, App run ok, but cannot access to environment variables, for example:

In Environment have this variable:
TESTVAR='Hello'

In Node App:
const testVar = process.env.TESTVAR
console.log(TESTVAR). ->result undefined

What's wrong?
Thanks
 

Cold-Egg

Administrator
#4
From my test, it works.

The attached file is the OLS configuration.

app.js
Code:
const http = require('http');

const hostname = '127.0.0.1';
const port = 3000;

const testVar = process.env.TESTVAR

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end(`${testVar}`);
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://:/`);
});
And page returns a "Hello" correctly.

Please make sure to restart the lsnode process with kill -9 PID command if you have any changes to the code.
 

Attachments

#5
Thanks for all the help, but I'm unable, I've been testing for I don't know how many hours and it doesn't work.

I don't understand
I give up :(
 
Top