Skip to main content

Command Palette

Search for a command to run...

Setting Up Your First Node.js Application Step-by-Step

Updated
โ€ข2 min readโ€ขView as Markdown

Step 1: Installing Node.js

  1. Go to the official website: https://nodejs.org

  2. Download the LTS (Long Term Support) version

  3. Install it like any standard application

๐Ÿ‘‰ LTS is recommended because it's stable and widely supported.


Step 2: Verify Installation

Open your terminal (Linux/macOS) or command prompt (Windows) and run:

node -v

You should see something like:

v20.x.x

Also check npm (Node Package Manager):

npm -v

Step 3: Understanding Node REPL

REPL = Read โ†’ Eval โ†’ Print โ†’ Loop

Start it by typing:

node

Now you can run JavaScript directly:

> console.log("Hello Node")
Hello Node

Why REPL matters:

  • Quick testing

  • Debugging small snippets

  • Learning JS behavior interactively

Exit REPL:

.exit

Step 4: Create Your First JavaScript File

Create a file:

touch app.js

Or manually create app.js and add:

console.log("Hello from Node.js!");

Step 5: Run the Script

Execute the file using:

node app.js

Output:

Hello from Node.js!

This confirms your Node environment is working correctly.


Step 6: Create a Simple "Hello World" Server

Now letโ€™s build a basic HTTP server.

Update app.js:

const http = require("http");

const server = http.createServer((req, res) => {
  res.end("Hello World from Node.js Server!");
});

server.listen(3000, () => {
  console.log("Server is running on http://localhost:3000");
});