Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node.js REPL "undefined"

Tags:

node.js

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
>
like image 696
7zark7 Avatar asked Apr 17 '12 06:04

7zark7


2 Answers

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

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

from the command line

like image 72
PerseP Avatar answered Oct 27 '22 10:10

PerseP


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)"
like image 28
deltanovember Avatar answered Oct 27 '22 10:10

deltanovember