18

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
>
7zark7
  • 10,015
  • 5
  • 39
  • 54

4 Answers4

17

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

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

from the command line

PerseP
  • 1,177
  • 2
  • 14
  • 22
12

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)"
Octavian Helm
  • 39,405
  • 19
  • 98
  • 102
deltanovember
  • 42,611
  • 64
  • 162
  • 244
  • I saw that, but sorry to be dense - I don't understand how to set this when running node from the command line. I'm not launching repl from a script. This mentions repl.start(...), etc. – 7zark7 Apr 17 '12 at 16:54
  • 2
    Expanding on @deltanovember's sample code, to get the behavior you want, use ``node -e "require('repl').start(null, null, null, null, true)"`` from the command-line. Perhaps alias it? –  Apr 17 '12 at 20:32
  • But what if I only want it to display undefined when it matters that undefined was returned? Like in the case of var and let where there was never a chance for anything to be returned? – still_dreaming_1 Aug 17 '16 at 17:54
7
# 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!

elbeardmorez
  • 580
  • 1
  • 5
  • 13
2

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
>
rg_dev
  • 41
  • 3