Javascript 我无法在node.JS中使用ES6语法
我已将节点更新为最新版本。 这是一段代码Javascript 我无法在node.JS中使用ES6语法,javascript,node.js,ecmascript-6,Javascript,Node.js,Ecmascript 6,我已将节点更新为最新版本。 这是一段代码 const fs = require('fs'); const textIn = fs.readFileSync('./txt/input.txt','utf-8'); console.log(textIn); const textOut = 'This is what we know: ${textIn}.\nCreated on ${Date.now()}'; fs.writeFileSync('./txt/output.txt', textO
const fs = require('fs');
const textIn = fs.readFileSync('./txt/input.txt','utf-8');
console.log(textIn);
const textOut = 'This is what we know: ${textIn}.\nCreated on ${Date.now()}';
fs.writeFileSync('./txt/output.txt', textOut);
console.log('File Written!');
问题是,当${textIn}作为字符串时,我可能会生成一个输出文件您需要将该字符串用倒勾而不是单引号括起来,以便能够将变量的值用作字符串:
const textOut = `This is what we know: ${textIn}.\nCreated on ${Date.now()}`;
const textOut = `This is what we know: ${textIn}.\nCreated on ${Date.now()}`;
您正在使用,因此需要反勾号,而不是双引号或单引号: