简体   繁体   中英

node.js REPL “undefined”

Upgraded from node 0.4.11 to 0.6.15, and noticed the REPL (running node with no arguments) keeps dumping "undefined" after most commands or carriages returns...

It's distracting and driving me batty, how do you disable this?

> 
undefined
> 
undefined
> 
undefined
> 
undefined
> var x = 2
undefined
> x
2
>

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)"
# 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!

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
>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM