node.js REPL "undefined"

On similar lines of this answer

You can run this repl.repl.ignoreUndefined=true from inside REPL session.

A sample code:

Welcome to Node.js v12.13.1.
Type ".help" for more information.
> var x
undefined
> repl.repl.ignoreUndefined=true
true
> var y = 10
> _
true
> console.log(y)
10
>

# node -i -e "repl.repl.ignoreUndefined=true"

My new _node alias (v6.11.2).

The advantage I see in this over others here, is that it affects the current/default repl context ..which is where all my node command history was!


Another way of invoking node without the undefined returns of commands is by:

node -e "require('repl').start({ignoreUndefined: true})"

from the command line


See the Node.js REPL documentation page.

Specifically this:

If ignoreUndefined is set to true, then the repl will not output return value of command if it's undefined. Defaults to false.

Sample code:

var net = require("net"),
    repl = require("repl");

repl.start(null, null, null, null, true);

Sample output:

> var x
> var blah

Additionally you could alias node to

node -e "require('repl').start(null, null, null, null, true)"

Tags:

Node.Js