I am writing a Node.js application using the tslint:recommended
rule set and it warns me about the usage of console.log
in my code:
src/index.ts[1, 1]: Calls to 'console.log' are not allowed.
What else should I be using? Should I use some sort of system.out
equivalent?
Here's my tslint.json
:
{
"extends": "tslint:recommended"
}
The node:console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: A Console class with methods such as console.
js provides a console module which provides tons of very useful ways to interact with the command line. It is basically the same as the console object you find in the browser. The most basic and most used method is console. log() , which prints the string you pass to it to the console.
It is stated in the eslint doc about the no-console
rule:
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.
So it is valid to deviate from the recommended ruleset here and hence I adapted my tslint.json
to match:
{
"extends": "tslint:recommended",
"rules": {
"no-console": false
}
}
Faster alternative to console.log:
process.stdout.write("text");
You will need to insert newlines yourself. Example:
process.stdout.write("new line\n");
Difference between "process.stdout.write" and "console.log" in node.js?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With