Wednesday, March 21, 2018

NodeJS - REPL - read-eval-print-loop

Node provides a REPL (read-eval-print-loop) interface, available by running node at the command line without any arguments. In a REPL we can write snippets of code - to get immediate results as each statement is written and executed.

REPL can be great for:

  • learning a programming language, 
  • running simple tests
  • debugging. 


Type node at the command prompt to start REPL:

~ $ node
> console.log("welcome to node")
welcome to node
undefined
> console.log(4*5)
20
undefined
> 4*5
20
> .help
.break    Sometimes you get stuck, this gets you out
.clear    Alias for .break
.editor   Enter editor mode
.exit     Exit the repl
.help     Print this help message
.load     Load JS from a file into the REPL session
.save     Save all evaluated commands in this REPL session to a file
> .exit
~ $ 


Reference:
NODE - repl and special keys 

No comments:

Post a Comment