We can start Node REPL by typing
Autocomplete — Tab & Tab Tab
Node REPL supports autocomplete using a tab key. At any point, we can press tab key to autocomplete partially typed command or expression. If there are multiple commands/expressions starting with partially typed text, then pressing tab second time (tab followed by tab) will show a list of possible commands with the typed prefix.
For example, typing ‘s’ and pressing tab key will show all possible valid expressions starting with ‘s’.
Try pressing tab followed by tab without entering anything and we can see all the modules exported by Node by default.
We can also see a list of apis/functions/properties available within a particular module/object by pressing the module/object name followed by a ‘.’ and pressing tab two times. For example, to see a list of functions/properties of Array, type Array. and press tab two times. We see a list of members exposed by Array.
Try pressing global. and tab. This will list all the modules and objects available to all the node scripts without explicitly importing/requiring them in the file.
Underscore(_) is a special variable in node which stores the result of last expression evaluation. It can be used to access result of last command execution — similar to $? in bash.
Special Dot Commands
Node REPL supports special commands which starts with a dot ‘.’. Type a . and press double tab to see a list of dot commands. Alternatively, type .help to see all dot commands with their description.
Then we can load it in current REPL session using .load as below.
.break & .clear
Break & Clear command can be used to terminate & come out of a multi line session. Sometimes while copy pasting code snippet into REPL, we get stuck. We can type .break to terminate a multi-line session in such cases and get back to REPL prompt.
Clear is just an alias for break command.
Press ^D to finish multi-line editing and ^C to cancel editing.
Save command would save entire session history to a file. This could be useful after a long REPL session.
Finally, .exit command will terminate the REPL session. By default to exit the current session, we need to press ^C twice. By typing .exit will directly exit the session.
Node REPL is very convenient and powerful tool during development. We have list down only a few features. It also allows us to create custom REPL sessions by requiring ‘repl’ module and invoking repl.start(). Refer Node REPL documentation for full list of features and possible customization.