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

168
Views
How to making live clock in single line console log format in NodeJS

In browser, we can making the live clock in single line display by using setInterval and replacing content inside HTML element like this:

var span = document.getElementById('span');

    function time() {
      var d = new Date();
      var s = d.getSeconds();
      var m = d.getMinutes();
      var h = d.getHours();
      span.textContent = 
        ("0" + h).substr(-2) + ":" + ("0" + m).substr(-2) + ":" + ("0" + s).substr(-2);
    }
setInterval(time, 1000);
<span id="span"></span>

But, how we can do it the same thing in terminal console with NodeJS? If we use console.log and setInterval it will create new line. Like this:

07:00:01
07:00:02
07:00:03
07:00:04

I just want to display console.log live clock in single line on terminal.

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

0

You w ant to use \r to terminate the previous line with stdout.

    setInterval(() => process.stdout.write(`${new Date()}\r`), 1000);
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!