我使用的是Node6.0。下面是代码。但是Node.js不能识别美元符号(“$”)why $ sign is not red?
const os = require('os');
const fs = require('fs');
var user = os.userInfo();
fs.appendFile("message.txt","${user.username}")我想把我的用户名写到message.txt
发布于 2018-01-02 16:19:32
使用`而不是“
fs.appendFile("message.txt", `${ user.username }`)发布于 2018-01-02 19:27:20
您正在尝试使用Template literals。
模板文字用反记号() (grave accent)字符括起来,而不是双引号或单引号。
因此,您应该使用`${user.username}`而不是"${user.username}"。
https://stackoverflow.com/questions/48057652
复制相似问题