0

I am trying to write an example for console.clear() method from console module of node.js

I have searched for it all across stackoverflow but is not able to find anything relevant.

console.log("Content printed in file");
console.clear();

P.S : I am not looking for a way to erase the content from console. I am aware that it can be achieved. I just want a simple example of how console.clear() method works.

Thanks.

Community
  • 1
  • 1
  • It's a function. You simply call it. What don't you understand? – SLaks Sep 14 '17 at 18:58
  • It's OS dependent -- [See Docs](https://nodejs.org/api/console.html#console_console_clear) – mhodges Sep 14 '17 at 18:59
  • It's not working....i am using windows 7.... –  Sep 14 '17 at 19:07
  • @mhodges i know that sir....i am using windows 7 and its not working.... –  Sep 14 '17 at 19:08
  • It is showing an error **console.clear()** is not a function –  Sep 14 '17 at 19:34
  • @trifler My guess is that you are on the latest stable version of Node, which is 6.11.X. This feature was added in Node.js version 8.3.0 (as per the documentation). Check your version with the command `node -v` and make sure you are on 8.3.0+ – mhodges Sep 14 '17 at 19:38

2 Answers2

0

From node.js docs https://nodejs.org/api/console.html#console_console_clear

When stdout is a TTY, calling console.clear() will attempt to clear the TTY. When stdout is not a TTY, this method does nothing.

TTY is a Unix Terminal found from this other SO answer; What is a TTY and how can I enable it on Ubuntu?

tty is one of those funky Unix commands that prints (or, displays) to standard output the name of the terminal connected to standard input.

Since your on windows I'm guessing it doesn't have TTY.

Jace
  • 144
  • 1
  • 9
0

Your code seems OK.

Please check what node.js version are you running ?

Note that you may get console.clear() is not a function if the function is not supported in your version. What I would suggest is that in case you're not running the current version [ current as of now is 8.5.0 ] , here in the docs for LTS [ 6.11.3 ]

docs for console

you'll find that there's no documentation for the function you're referring to.

just try to update to the current version [8.5.0] not LTS and then check.

Here's a link to official node.js site where you can find the latest node.js version ::

Download Latest Node.js

Rishabh.IO
  • 591
  • 7
  • 6
  • Thanks @rishabh.io.....I was using 6.9.4....After updating the version...the code works fine.... –  Sep 14 '17 at 19:55