不能在node.js中使用模板字符串

Can't use template strings in node.js

本文关键字:字符串 node js 不能      更新时间:2023-09-26

根据MDN,模板字符串应该在Chrome中工作,并通过扩展V8对Node.js是基于;但是当我尝试以下操作时,我得到一个语法错误:

var name = 'coffee';
console.log(`Hello, ${name}!`);

运行node file.js只会导致SyntaxError: Unexpected token ILLEGAL

是否有某种标志我需要启用使用此功能,或者它根本没有在节点中实现?

模板字符串在NodeJS v4.0.0中添加。我可以确认它们至少可以追溯到v4.1.1;我没有检查v4.0.0,但我没有理由怀疑链接的公告。