NodeJS, ES6, and Template Literals

If you have updated NodeJS to the latest release, at today v4.0.0, you are already able to use some of the new specs for ES6, the incoming new Javascript engine.

For example, you should be able to use template literals, as shown below.

var name = "Juan",
    job = "flying penguin";

var sentence = `Hello ${name}, the ${job}!`;
console.log(sentence); // -> Hello Juan, the flying penguin!

If you look carefully, the string for sentence is wrapped within two backticks (or backquotes, also known as grave accents) instead of the usual + concatenator. ES6 allows the use of the new syntax so that variables can be used within a string if wrapped within a dollar sign and two curly braces.


However, at the present ES6 will work only within NodeJS and only if you add a jsconfig.json file in the same folder of your app with the following content.

  "compilerOptions": {
    "target": "ES6"