Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear command history of NodeJS REPL Console

I am using NodeJS version 4.2.1

I want to know the command for clearing the NodeJS REPL console history completely so it doesn't show previously executed commands when Up or Down arrow keys are pressed.

Any suggestions ?

like image 302
Vicky Dev Avatar asked Oct 14 '15 20:10

Vicky Dev


People also ask

How do you clear a node in REPL?

You can add functionality to node's REPL so that you can clear it in the same way your can clear Chrome's JavasSript Developer Console. If you copy and paste this function into the nodejs console, you can then call clear(); each time you want to clear the screen.

What is the command to stop REPL in node JS?

To exit the REPL, you can type . exit , or press CTRL+D once, or press CTRL+C twice, which will return you to the shell prompt.


2 Answers

Per the nodejs documentation which can be found at the following link:

nodejs repl

Environment Variable Options

The built-in repl (invoked by running node or node -i) may be controlled via the following environment variables:

NODE_REPL_HISTORY - When a valid path is given, persistent REPL history will be saved to the specified file rather than .node_repl_history in the user's home directory. Setting this value to "" will disable persistent REPL history. NODE_REPL_HISTORY_SIZE - defaults to 1000. Controls how many lines of history will be persisted if history is available. Must be a positive number. NODE_REPL_MODE - may be any of sloppy, strict, or magic. Defaults to magic, which will automatically run "strict mode only" statements in strict mode.

Persistent History

By default, the REPL will persist history between node REPL sessions by saving to a .node_repl_history file in the user's home directory. This can be disabled by setting the environment variable NODE_REPL_HISTORY="".

like image 127
user2263572 Avatar answered Sep 26 '22 12:09

user2263572


The answer is actually simple :)

On Windows (my version is 10):

  1. go to user folder: cd %userprofile%
  2. empty file named .node_repl_history (in my case with vim text-editor) OR you can simple run: echo. > .node_repl_history and it will have same effect.
like image 31
Gaja Avatar answered Sep 25 '22 12:09

Gaja