我正在使用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"
}
答案 0 :(得分:16)
eslint doc中有关no-console
规则的说明:
何时不使用
但是,如果您正在使用Node.js,则控制台用于向用户输出信息,因此不严格用于 调试目的。如果您正在为Node.js开发,那么最多 可能不希望启用此规则。
因此,在此偏离推荐的规则集是有效的,因此我调整了我的tslint.json
以匹配:
{
"extends": "tslint:recommended",
"rules": {
"no-console": false
}
}
答案 1 :(得分:0)
更快地替代console.log:
process.stdout.write("text");
您需要自己插入换行符。例如:
process.stdout.write("new line\n");
Difference between "process.stdout.write" and "console.log" in node.js?