Nodemon: [Feature request] add option to clear the console when restarting

Created on 17 Apr 2018  ·  9Comments  ·  Source: remy/nodemon

Currently, I'm doing this:

//clear.js
console.log('\x1Bc');
//index.js
console.log('something something');
//package.json
"scripts": {
  "run": "nodemon -q -x \"node clear && node index\""
}

I want to clean the console everytime nodemon restarts the process

Most helpful comment

This is what the nodemon events are for. You can include either a global or local nodemon.json file as per the following to do what you're after.

As per the design principles, I'd rather re-use the current tech rather than introduce new features:

{
  "events": {
    "start": "echo \"\\x1Bc\""
  }
}

All 9 comments

I can add a PR if you think this is worth it

Actually you can do this almost natively in Node, and even in browsers with

console.clear()

An option for that wouldn't really be that useful.

While I agree with you, my use case is very specific: I'm teaching javascript and I don't want to add a console.clear on top of every file and say "console is something we haven't studied yet, but we're using this to clear the console etc". I just want a clean file. I understand it's not a big deal for most people, I just thought it'd be a good option to have.

This is what the nodemon events are for. You can include either a global or local nodemon.json file as per the following to do what you're after.

As per the design principles, I'd rather re-use the current tech rather than introduce new features:

{
  "events": {
    "start": "echo \"\\x1Bc\""
  }
}

I didn't think about this. Thanks!

Nice solution!

Regarding implementation, Windows and some shells may not support hex code escaping, so if you want to allow people running the thing on more platforms, you can change it to:

{
  "events": {
    "start": "node -e console.clear()"
  }
}

on Ubuntu 18.04 I had to put single quotes around 'console.clear'

I had issues with "start": "node -e console.clear()". So instead I just have

"events": {
    "start": "clear"
}

I use this in command line

nodemon -x "clear;node" file.js
Was this page helpful?
0 / 5 - 0 ratings

Related issues

piton13 picture piton13  ·  3Comments

Mohammad-Quanit picture Mohammad-Quanit  ·  5Comments

dimsmol picture dimsmol  ·  4Comments

robboerman picture robboerman  ·  3Comments

medoix picture medoix  ·  4Comments