I have a number of bash/shell variables in a file, I would like to read them into a node.js script (or javascript I guess) to eval them and set javascript variables.
e.g. the file contains:
gateway_ip=192.168.1.1
mask=255.255.255.0
port=8080
I've tried the following:
function readConfigFile() {
var filename="/home/pi/.data-test";
fs.readFile(filename, 'utf8', function(err, data) {
var lines = data.split('\n');
for(var i = 0; i < lines.length-1; i++) {
console.log(lines[i]);
eval(lines[i]);
console.log(gateway_ip);
}
});
}
and it spits out the lines as text, but I doesn't seem to be able to make the javascript variable. The error is:
undefined:1 default_gateway=192.168.1.1
Is there something obvious I've missed here?
requireas Object