My Development Notes


Getting started with NodeJS REPL

NodeJS

First go to the NodeJS website and download a suitable version of NodeJS on your system. I would recommend you use an LTS version in order to keep getting long term support and updates. Next, test whether you’ve NodeJS installed on your system by running the following terminal commands :

node -v

To type and run node codes directly on your terminal, type node and hit Enter inside the terminal. This opens up the node REPL (read-eval-print loop). Here, you can write and run JavaScript (or node) codes just like you do inside your browser. This is because NodeJS is just a JavaScript runtime environment, as you might already know. So, here JS is actually running on the local server and not on the browser.

In order to exit the REPL, we can type in any of the following instructions :

  • .exit
  • Ctrl + D

To clear the REPL type Ctrl + K

When inside the node REPL, when you hit Tab, you can get a list of all the global variables and codes to use in NodeJS.

The underscore(_) key gives you the previous result.

Here are some additional REPL commands :

  • .help – Displays all available REPL commands.
  • .break – Sometimes used to exit a multi-line expression.
  • .clear – Resets the REPL context.

Leave a Reply

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