I have this JSON config for a backend CLI utility:
{
"searchRoots": ["$HOME"],
"list": []
}
if I did this with JavaScript, I would do:
module.exports = {
searchRoots": [process.env.HOME],
list: []
};
the problem with using JSON instead of JS, is that I cannot programmatically reference environment variables or any variables really, everything is hardcoded.
So what I will do in my Node.js code, is do:
const conf = require('./conf.json');
const searchRoots = conf.searchRoots.map(function(item){
return process.env[item];
});
Is there another good way to do this? Without env variables?
What is the best way to include some sort of variable in JSON that can be interpreted by the reader of the file?
Is there a way to do bash-style interpretation of the path via Node.js?