concept REPL in category node

appears as: REPL, REPL
Get Programming with Node.js

This is an excerpt from Manning's book Get Programming with Node.js.

In this section, you begin using Node.js from terminal through the Node.js REPL environment. The interactive Node.js shell is the Node.js version of Read-Evaluate-Print Loop (REPL). This shell is a space in which you can write pure JavaScript and evaluate your code in the terminal window in real time. Within the window, your written code is read and evaluated by Node.js, with results printed back to your console. In this section, I look at a few things you can do in REPL.

When you have Node.js installed, your first stop in running your code is in the Read-Evaluate-Print Loop (REPL). This interactive environment is similar to the console window in a Chrome web browser. In REPL, you’re able to run any JavaScript code. You can al so require Node.js modules to test aspects of your application.

A.2.1. Running JavaScript in REPL

To start REPL, navigate to any terminal window on your computer and enter node. This command immediately returns a prompt (>), after which you may enter any JavaScript statements. You can think of REPL as a running Node.js application that responds to your commands instantaneously. That is, you don’t need to write your JavaScript code in a separate file and then run it; you can type that JavaScript code directly in the REPL window. Try defining a couple of variables, as shown in the next listing. You’ll notice that with each JavaScript statement you run, REPL outputs the return value of that statement. For variable assignment, the return value is undefined.

Listing A.9. Defining variables in REPL
> let x = 42;
undefined
> let sentence = "The meaning of life is ";
undefined
Node.js in Practice

This is an excerpt from Manning's book Node.js in Practice.

Certain classes of Node programs benefit from turning off Nagle’s algorithm. For example, you may have created a REPL that transmits a single character at a time as the user types messages, or a game that transmits location data of players. The next listing shows a program that disables Nagle’s algorithm.

We were in a REPL for a while, so we likely lost context when we were paused. Let’s use list again to get our bearings: