Clear command history of NodeJS REPL Console
Asked Answered
I

3

13

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 ?

Intromit answered 14/10, 2015 at 20:27 Comment(0)
T
14

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.
Tallula answered 26/1, 2016 at 15:3 Comment(2)
Works for Ubuntu 20.04 - can be found in $HOME/.node_repl_historyGradely
Also works on Mac Monterey 12.0.1 - file is also located at ~/.node_repl_historySneaking
C
10

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="".

Cooney answered 22/11, 2015 at 2:4 Comment(0)
B
0

In your node js server just do like this :

    app.listen(5600,() => {
        console.clear();
        console.log('Server app listening on port 5600');
    });
Blowbyblow answered 29/3, 2023 at 9:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.