k0pernikus
k0pernikus

Reputation: 66676

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

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"
}

Upvotes: 6

Views: 13599

Answers (2)

jaggedsoft
jaggedsoft

Reputation: 4038

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?

Upvotes: 4

k0pernikus
k0pernikus

Reputation: 66676

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
    }
}

Upvotes: 23

Related Questions