Running Node.js and Writing Basic Scripts

Learn to run Node.js, use the Node REPL, and execute your first script.

Node.js is a runtime environment, so it doesn't have its own graphical interface. We interact with Node.js through a command-line interface (CLI). In this lesson, we’ll learn to run Node.js, use its interactive environment (REPL), and create a basic script. Once we’re comfortable with this, we’ll have taken our first steps into server-side JavaScript.

Running Node.js in interactive mode (REPL)

The Node.js REPL lets us interact with JavaScript directly. REPL stands for Read-Eval-Print Loop:

  • Read: It reads the input.

  • Eval: It evaluates the input as JavaScript code.

  • Print: It prints the result of the evaluation.

  • Loop: It waits for the next command.

Using the REPL is a quick way to test ideas, debug code, or try out JavaScript features. Code typed in the REPL isn't saved, so for anything you want to reuse, write a script instead. Let’s get started.