REPL Terminal in Node.js
REPL is an acronym for Read Eval Print Loop (understandably: Reading - Evaluating - Printing - Repeating) and it represents the computer environment like the console screen in the Linux shell where you can type the command line and the system The system will return the results. Node.js also has a REPL environment. It to perform the desired tasks:
Read : Read user input information, convert into Javascript data and store in memory.
Eval : Evaluate these data structures.
Print : Print the results.
Loop : Repeat the command line until the user types ctrl-c twice.
The REPL feature of Node js is very useful when you use Node.js for the purpose of debugging code.
Start with REPL in Node.js
REPL can start by simply on the shell / console screen without using any of the following parameters:
$ node
You will see the REPL> prompt prompt. Here, you can type any command in Node.js.
$ node
>
Simple expressions in Node.js
Below I introduce some simple expressions that can be used at the REPL command prompt in Node.js:
$ node
> 1 + 3
4
> 1 + (2 * 3) - 4
3
>
Use variables in Node.js
You can use variables to store values and then print the value of the same variable as in traditional code snippets. If not using the var keyword, the value will be stored in the variable and printed. Meanwhile if the var keyword is used, the value is stored and may not be printed. You can print variables using console.log ().
$ node
> x = 10
ten
> var y = 10
undefined
> x + y
20
> console.log ("Hello World")
Hello World
undefined
Expressions on multiple lines in Node.js
The REPL node supports expressions that reside on many similar lines as in Javascript. Together check the do-while expression in the following action:
$ node
> var x = 0
undefined
> due to {
. x ++;
. console.log ("x:" + x);
.} while (x <5);
x: 1
x: 2
x: 3
x: 4
x: 5
undefined
>
The dashes . display automatically when you press the Enter key after the opening parenthesis. Node.js will automatically check to see if the expression is continuing.
The variable has an underscore in Node.js
You can use underscores _ to get the final result of the calculation:
$ node
> var x = 10
undefined
> var y = 20
undefined
> x + y
30
> var sum = _
undefined
> console.log (sum)
30
undefined
>
Introducing some REPL commands in Node.js
ctrl + c - End the current command.
Press ctrl + c twice - End Node REPL.
ctrl + d - End of the REPL node.
Up / Down arrow keys - View the history of commands, check the previous command and can modify previously edited commands.
Tab key - List of current commands.
.help - List all commands.
.break - Exit an expression that sits on multiple lines (eg, do-while).
.clear - Exit an expression that sits on multiple lines
.save ten_file - Save the current Node.js REPL session to a certain ten_file.
.load ten_file - Download the content of the current Node.js REPL ten_file.
Finish REPL in Node.js
As mentioned above, you need to press ctr + c twice to end the Node.js REPL.
$ node > (^C again to quit) >
According to Tutorialspoint
Last lesson: Hello World program in Node.js
Next article: NPM in Node.js
You should read it
May be interested
- How to customize Terminal on Macif you use terminal on a mac, you should change the look and some other features of this window for better productivity.
- Top 7 best Linux terminal emulatorsterminal is pre-installed in most linux distributions. however, you may not get as many customization options and advanced functionality with the default option.
- Windows Terminal is about to have a retro version with a 'classic' interface.windows terminal will receive a series of 'classic' retro-style crt effects.
- Windows Terminal can now automatically launch configurations as administratormicrosoft has officially released a new version of windows terminal 1.13, which comes with a long-awaited feature that allows automatic launch of profiles as an administrator.
- How to make Windows Terminal the default Terminal application and its benefitsyou can set windows terminal as your default terminal application whenever you launch command prompt or powershell.
- How to use Guake Terminal in Linuxfor many years, the terminal in linux remained unchanged. after all, there may not be much to fix or improve in a command prompt window. but guake proved this thinking wrong.
- How to reset Windows Terminal to default settings on Windows 10windows terminal allows you to customize many different setup options. this is also the highly appreciated factor of this tool. however, if i have made too many changes to the windows terminal and want to revert to the default settings, what should i do? ,
- 6 ways to fix Windows Terminal not opening errorwindows terminal is a pretty effective tool as it allows you to type in a variety of command line tools for both windows 10 and 11. this sounds good as long as you can open it.
- Integrated terminal in SQL Operations Studio (preview)in sql operations studio (preview), you can open an integrated terminal, starting from the root of the current workspace.
- 18 terminal commands on Chromebook you should knowdo you know that chromebooks have an integrated terminal? chrome os developer shell, or crosh for short, allows users to access the command line interface, which can be used for debugging, testing, etc.