Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

215
Views
How do you dynamically change/overwrite a console log with Node.js?

I'm working with JavaScript/Node and have a Websocket with a server that is sending a constantly updating string. My goal is to log the string dynamically in the console, so if the sequence of strings from the stream is [string1, string1, string2, string2, string2, string3], then rather than have the console show

string1
string1
string2
string2
string2
string3

I want the console to show

stringI

Where stringI is constantly updating and I is in {1,2,3}

Currently, I'm doing this with

process.stdout.clearLine(0)
process.stdout.cursorTo(0)
process.stdout.write(new_string)

But I run into issues when the string is greater than one line length in the console.

Does anyone know how I can dynamically overwrite a constantly updating string in the console? Thanks!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

truncation could be an easy option:

const { exec } = require("child_process");
exec("truncate -s 0 console.log");
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!