I'm trying to interpolate a string loaded from a file in node.js without success.
The file contains template substitutions like: ${js-stuff}, which I want to resolve in the scope of whenever I evaluate the variable within the backticks.
I'm calling the string which contains the text loaded from the file 'template'.
I hoped console.log(`${template}`)
would recursively resolve the template substitutions inside the template variable and print the result, but it seems as if I'm wrong as only the template-string get's printed out without it's template substitutions being resolved.
As the string interpolation doesn't work recursively, I would have to do something like console.log(``${template}``)
, but I'm not quite sure how.
Using the eval function I got it working like this:
console.log(eval(`\`${template}\``));
But this doesn't seem like the best way to do this?
TDLR; I don't want to evaluate a single variable using string interpolating, I want to evaluate a variable which contains a string consisting of a template substitution.