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

2

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"
}
Pritchett answered 29/9, 2016 at 11:47 Comment(0)
P
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
    }
}
Pritchett answered 29/9, 2016 at 11:47 Comment(4)
false should be 0 (at least this is the case for my version of eslint).Linkous
this is tslint not eslintDamsel
@Damsel That doesn't affect the reasoning on when no to use the no-console rule.Pritchett
but what if I am just in a regular process of debugging in ReactJS, is there other way of debugging and not using the console.logHufford
D
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?

Dotty answered 29/8, 2017 at 21:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.