5

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"
}
Nisse Engström
  • 4,738
  • 23
  • 27
  • 42
k0pernikus
  • 60,309
  • 67
  • 216
  • 347

2 Answers2

23

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
    }
}
k0pernikus
  • 60,309
  • 67
  • 216
  • 347
3

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?

jaggedsoft
  • 3,858
  • 2
  • 33
  • 41