Armand Grillet
Armand Grillet

Reputation: 3399

Using String.raw() with Node JS

I'm working on a Node.js app with and I would like to use String.raw() which is part of the ES 6 standard.

However, when using it as in the documentation:

text = String.raw`Hi\n${2+3}!` + text.slice(2);

It returns SyntaxError: Unexpected token ILLEGAL for the character after String.raw.

I think that there is a problem because String.raw() is a new technology only available for Chrome and Firefox yet. However, can I use it in Node.js and how?

Upvotes: 0

Views: 2146

Answers (1)

Roland Szabo
Roland Szabo

Reputation: 153

The grave character after raw denotes template strings, which is a feature in ES6 Harmony. You can invoke node with --harmony flag, but this feature is not yet implemented. This is the reason of the syntax error. Raw strings are unsupported too. If you want experimenting with this feature in server side, check out io.js, which is a fork of node, but with many ES6 features implemented and enabled by default.

Upvotes: 2

Related Questions