node.js REPL “undefined”

前端 未结 4 1697
醉梦人生
醉梦人生 2020-12-03 05:48

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

相关标签:
4条回答
  • 2020-12-03 06:02

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

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

    from the command line

    0 讨论(0)
  • 2020-12-03 06:17

    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)"
    
    0 讨论(0)
  • 2020-12-03 06:19

    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
    >
    
    0 讨论(0)
  • 2020-12-03 06:23
    # 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!

    0 讨论(0)
提交回复
热议问题