Node.js REPL


Node.js provides us with an interactive code execution known as REPL (Read-Eval-Print-Loop) where you can execute and run code on the shell.

  • Read: Read user's inputs, and parses it into a data structure in memory.
  • Eval: Takes this internal data structure and evaluates it.
  • Print: taking the result yielded by eval, and prints it out to the user.
  • Loop: repeat the steps above.

To do so open your shell or cmd and type: node.

> node
Welcome to Node.js vX.Y.Z.
Type ".help" for more information.

Hello world with REPL

Since Node.js uses javascript you can run any javascript code there, and of course once you learn Node.js you can import libraries, use Node.js core system, etc.

> console.log("hello world")
hello world
> 4+4
> [1,2,3].reduce((u,v)=>u+v,0)
> var x = "hello"
> let y = "world"
> let hello = x + " " + y
> console.log(hello)
hello world

To quit the REPL type "ctrl+c" twice.