remy / nodemon

Monitor for any changes in your node.js application and automatically restart the server - perfect for development
http://nodemon.io/
MIT License
26.23k stars 1.72k forks source link

Fixed console output interrupts readline with nodemon #2048

Closed dement6d closed 2 years ago

dement6d commented 2 years ago

Nodemon behavior VS normal node behavior:

https://user-images.githubusercontent.com/93228501/177019648-8ddf8bb3-bcdf-4f62-bb48-69f4a33c338e.mp4

Steps to reproduce

Create index.js with the following code:

import readline from "readline";

setInterval(() => console.log('hello'), 1000)

var cli = readline.createInterface(process.stdin, process.stdout);
cli.setPrompt("\x1b[0;32m \x1b[0;37m");
fixStdoutFor(cli);

cli.on('line', function (line) {
  console.log("You entered: " + line)
  cli.prompt();
});
cli.prompt();

function fixStdoutFor(cli) {
  var oldStdout = process.stdout;
  var newStdout = Object.create(oldStdout);
  newStdout.write = function () {
    cli.output.write('\x1b[2K\r');
    var result = oldStdout.write.apply(
      this,
      Array.prototype.slice.call(arguments)
    );
    cli._refreshLine();
    return result;
  }
  process.__defineGetter__('stdout', function () { return newStdout; });
}

Run nodemon index.js

github-actions[bot] commented 2 years ago

This issue has been automatically marked as idle and stale because it hasn't had any recent activity. It will be automtically closed if no further activity occurs. If you think this is wrong, or the problem still persists, just pop a reply in the comments and @remy will (try!) to follow up. Thank you for contributing <3

github-actions[bot] commented 2 years ago

Automatically closing this issue due to lack of activity