【问题标题】:Node.js os library not giving desired outputNode.js 操作系统库未提供所需的输出
【发布时间】:2018-06-19 06:39:41
【问题描述】:
console.log('Starting App');

const fs = require ('fs');
const os = require ('os');

var user = os.userInfo();


fs.appendFileSync('message.txt',  'Hello  ${user.username}!');

【问题讨论】:

  • 输出:你好 ${user.username}!

标签: node.js node-modules


【解决方案1】:

问题不是os,问题是你没有使用template literals,它应该用反引号(`)包裹,而不是用单引号。

fs.appendFileSync('message.txt',  `Hello  ${user.username}!`);
//                                ` instead of '

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-18
    • 2016-09-19
    • 2015-01-12
    • 2023-01-05
    • 2022-01-24
    • 2021-06-05
    • 1970-01-01
    • 2023-03-12
    相关资源
    最近更新 更多