Hello World & REPL
Getting started with Node.js is easy. In this guide, we will run our first script and explore the interactive terminal.
Run Your First Script
- Create a file named
app.js. - Add the following code:
console.log("Hello, Node.js!");
- Run it from your terminal:
Terminal window node app.js
You should see Hello, Node.js! printed in your console.
The REPL (Read-Eval-Print Loop)
The REPL is an interactive environment where you can execute JavaScript code line by line. It’s great for testing small snippets.
How to use it:
- Open your terminal and type
node. - Start typing JavaScript:
> 2 + 24> const name = "Antigravity"undefined> `Hello ${name}`'Hello Antigravity'
Useful REPL Commands:
.exitorCtrl + C(twice): Exit the REPL..help: See all available commands..clear: Resets the context.
[!TIP] Use the REPL to quickly test a new JavaScript method or debug a logic piece before putting it into a file.