How to write multiple lines of code in Node REPL

后端 未结 5 2159
一个人的身影
一个人的身影 2020-12-23 19:35

I would like to evaluate

var foo = \"foo\";
console.log(foo);

as a block, instead of evaluating line by line

var foo = \"f         


        
5条回答
  •  青春惊慌失措
    2020-12-23 19:49

    Node v6.4 has an editor mode. At the repl prompt type .editor and you can input multiple lines.

    example

    $ node                                                                                                   
    > .editor
    // Entering editor mode (^D to finish, ^C to cancel)
    const fn = there => `why hello ${there}`;
    fn('multiline');
    // hit ^D 
    'why hello multiline'
    > // 'block' gets evaluated and back in single line mode.
    

    Here are the docs on all the special repl commands https://nodejs.org/api/repl.html#repl_commands_and_special_keys

提交回复
热议问题