我还应该使用什么来替代 nodejs 中的控制台?

What else should I use for an alternative to console in nodejs?

我正在使用 tslint:recommended 规则集编写 Node.js 应用程序,它会警告我在代码中使用 console.log

src/index.ts[1, 1]: Calls to 'console.log' are not allowed.

我还应该使用什么?我应该使用某种 system.out 等价物吗?

这是我的 tslint.json:

{
  "extends": "tslint:recommended"
}

关于no-console规则的eslint doc中有说明:

When Not To Use It

If you’re using Node.js, however, console is used to output information to the user and so is not strictly used for debugging purposes. If you are developing for Node.js then you most likely do not want this rule enabled.

因此偏离此处推荐的规则集是有效的,因此我调整了我的 tslint.json 以匹配:

{
    "extends": "tslint:recommended",
    "rules": {
        "no-console": false
    }
}

console.log 的更快替代方案: process.stdout.write("text");

您需要自己插入换行符。示例:

process.stdout.write("new line\n");

Difference between "process.stdout.write" and "console.log" in node.js?