Node.js: printing to console without a trailing newline?

后端 未结 8 2161
-上瘾入骨i
-上瘾入骨i 2020-11-28 00:27

Is there a method for printing to the console without a trailing newline? The console object documentation doesn\'t say anything regarding that:

相关标签:
8条回答
  • 2020-11-28 00:53

    I got the following error when using strict mode:

    Node error: "Octal literals are not allowed in strict mode."

    The following solution works (source):

    process.stdout.write("received: " + bytesReceived + "\x1B[0G");
    
    0 讨论(0)
  • 2020-11-28 01:00

    There seem to be many answers suggesting:

    process.stdout.write
    

    Error logs should be emitted on:

    process.stderr
    

    Instead use:

    console.error
    

    For anyone who is wonder why process.stdout.write('\033[0G'); wasn't doing anything it's because stdout is buffered and you need to wait for drain event (more info).

    If write returns false it will fire a drain event.

    0 讨论(0)
提交回复
热议问题