Repl Node.js

REPL (Read Eval Print Loop) is a structure that allows command interpreters in operating systems to write, read and compile commands line by line.

To start the Node.js REPL interpreter, simply type and run the following command in the operating system command interpreter.

After running the Node.js REPL interpreter, we can write Node.js commands.

Hello to the screen let’s print Node.js.

With the REPL interpreter, we can also do various arithmetic operations.

Using a variable

Using the Node.js REPL interpreter and defining a variable are as follows.

You can use the defined variable until the Node.js REPL interpreter closes

When developing projects with Node.js, writing commands on the REPL screen is not the preferred method.

REPL shortcuts

  • Ctrl + c – Terminates the running command.
  • Ctrl + c – Repeating the REPL interpreter twice.
  • Ctrl + d – Turns off the REPL interpreter.
  • Up / Down arrow keys – Use to scroll through commands.
  • Tab key – Gives a list of commands.
  • (Start character) Tab key – Gives commands for the start character. For example; n Tab key

REPL commands

.break command

Used to exit the command.

For example; Let’s say you forgot to create the variable to use in the following loop.

When you type and execute the command, it will wait for the command to continue.

With the .break command, you can terminate the command without further typing.

.clear command

It has the same function as the .break command.

.editor command

Instead of writing each command separately, it opens a vi, vim, nano-like editor on Linux operating systems.

Allows you to write commands line by line.

You can run commands with Ctrl + d or exit the editor with Ctrl + c.

.exit command

Used to turn off the REPL interpreter.

.help command

Node.js returns a list of REPL commands.

.load command

This is a command that is used to open, execute and use Node.js commands in the REPL session.

.save command

Used to save the written REPL commands to the file.

After writing the following code to the REPL interpreter

save hello.js will create a file named hello.js in the directory that the command interpreter points to and save the written code.

Run the Node.js commands

Save the following commands as the file name hello.js in any directory.

place the command interpreter location for your operating system in the directory where you saved it.

Type the following commands into the command interpreter.

The commands in the file will be executed and the result will appear in the command interpreter.



if you have question do not forget to write from the chat button next to it or from the comment

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *