Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions pages/command-line/how-to-use-the-nodejs-repl.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,12 @@ If you press the `up` arrow key, you will get access to the history of the previ

The REPL has some special commands, all starting with a dot `.`. They are

- `.help`: shows the dot commands help
- `.editor`: enables editor mode, to write multiline JavaScript code with ease. Once you are in this mode, enter ctrl-D to run the code you wrote.
- `.break`: when inputting a multi-line expression, entering the .break command will abort further input. Same as pressing ctrl-C.
- `.clear`: resets the REPL context to an empty object and clears any multi-line expression currently being input.
- `.load`: loads a JavaScript file, relative to the current working directory
- `.save`: saves all you entered in the REPL session to a file (specify the filename)
- `.exit`: exits the repl (same as pressing ctrl-C two times)
- `.help`: shows the dot commands help.
- `.editor`: enters editor mode, to write multiline JavaScript code.
Comment thread
zZMoZz marked this conversation as resolved.
- `.break` / `.clear`: exits multi-line code like functions. same as pressing ctrl-C.
Comment thread
zZMoZz marked this conversation as resolved.
Outdated
- `.load`: loads a JavaScript file, relative to the current working directory.
- `.save`: saves all commands you entered in the session to a file.
Comment thread
zZMoZz marked this conversation as resolved.
- `.exit`: exits the REPL (same as pressing ctrl-C two times).
Comment thread
zZMoZz marked this conversation as resolved.
Outdated

The REPL knows when you are typing a multi-line statement without the need to invoke `.editor`.

Expand All @@ -112,6 +111,12 @@ and you press `enter`, the REPL will go to a new line that starts with 3 dots, i

If you type `.break` at the end of a line, the multiline mode will stop and the statement will not be executed.

`.clear` clear the whole REPL context like restarting the session only in a custom REPL created programmatically:

```console
require('repl').start();
```

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this added?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested .clear in the terminal REPL, but it doesn't actually reset the REPL context, variables are stayed there. I tested it also now in a code file, the same thing so I believe I should remove this note.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the code recently. Can you check it?

### Run REPL from JavaScript file

We can import the REPL in a JavaScript file using `repl`.
Expand Down
Loading