Skip to main content
Madhukar
All Articles

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

August 7, 20265 min read
Node.jsBackendJavaScriptTutorial
Setting Up Your First Node.js Application Step-by-Step

Every Node.js developer starts in the exact same place: an empty terminal, and a decision to actually run JavaScript outside a browser for the first time. This guide walks through that entire journey, step by step — installing Node, confirming it works, exploring what the REPL actually is, writing your first script, and finishing with a real (if tiny) Hello World server. No frameworks, no shortcuts — just Node itself, from the ground up.

Step 1: Installing Node.js

Node.js is available for Windows, macOS, and Linux, and the installation process is largely the same in spirit across all three:

  1. Go to the official Node.js website (nodejs.org)
  2. Download the LTS (Long-Term Support) version — the recommended, stable choice for most learning and production use
  3. Run the installer for your operating system and follow the on-screen steps

Alternatively, many developers on macOS or Linux prefer installing Node through a package manager (like Homebrew on macOS, or your distribution’s package manager on Linux) — functionally equivalent, just a different installation path to the same result.

Step 2: Checking Installation Using Terminal

Once installed, open your terminal (Command Prompt or PowerShell on Windows, Terminal on macOS/Linux) and check that Node.js is actually available:

node -v

This should print a version number, like:

v20.11.0

It’s also worth checking npm (Node’s package manager, installed automatically alongside Node):

npm -v
10.2.4

If either command isn’t recognized, it usually means the installation didn’t complete successfully, or your terminal needs to be restarted to pick up the newly installed program — closing and reopening your terminal window resolves this in most cases.

Step 3: Understanding Node REPL

Before writing an actual file, it’s worth understanding a tool you’ll likely use constantly: the REPL — short for Read, Eval, Print, Loop. It’s an interactive environment where you type JavaScript directly into the terminal, and see the result immediately, line by line.

  • Read — it reads the JavaScript you type
  • Eval — it evaluates (runs) that code
  • Print — it prints the result
  • Loop — it goes back to waiting for your next line, repeating the cycle

Open it by simply typing:

node

Your terminal prompt changes to >, meaning you're now inside the REPL:

> 2 + 2
4
> const greeting = "Hello, Node!";
undefined
> greeting
'Hello, Node!'

This is an excellent way to quickly test small snippets of JavaScript without creating a file at all — genuinely useful for experimenting, not just a novelty. Exit the REPL at any time with .exit, or Ctrl + C pressed twice.

Step 4: Creating Your First JS File

The REPL is great for quick experiments, but real programs live in files. Create a new file named app.js in a folder of your choice, using any text editor (VS Code is a common choice, but any plain text editor works):

// app.js
console.log("Hello, Node.js!");

const sum = 5 + 10;
console.log(`5 + 10 = ${sum}`);

This is a completely ordinary JavaScript file — nothing Node-specific about the syntax itself yet. What makes it a “Node.js file” is simply that we’re about to run it with Node, rather than inside a browser.

Step 5: Running the Script Using the node Command

In your terminal, navigate to the folder containing app.js, and run:

node app.js

You should see:

Hello, Node.js!
5 + 10 = 15

That’s the entire execution flow: Node.js reads your file, runs it top to bottom just like any JavaScript engine would, and prints anything you explicitly logged along the way.

If you see an error instead, double-check that you’re running the command from inside the same folder as app.js — a very common early stumbling block is simply being in the wrong directory when the command runs.

Step 6: Writing a Hello World Server

Running a script is one thing — but Node.js is most known for building servers. Let’s build the simplest possible one, using Node’s built-in http module (no external frameworks needed):

// server.js
const http = require("http");

const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader("Content-Type", "text/plain");
res.end("Hello, World!");
});

const PORT = 3000;
server.listen(PORT, () => {
console.log(`Server running at http://localhost:${PORT}`);
});

What this code actually does

  • require("http") — loads Node's built-in module for creating HTTP servers
  • http.createServer(...) — creates a server, with a function that runs every time a request comes in
  • res.end("Hello, World!") — sends that exact text back as the response
  • server.listen(PORT, ...) — starts the server, listening for requests on port 3000

Run it the same way as before:

node server.js
Server running at http://localhost:3000

Now open a browser and visit http://localhost:3000 — you should see Hello, World! displayed directly on the page. Your terminal keeps running (it doesn't return to a normal prompt) because the server is actively listening, ready to respond to any request that comes in — stop it anytime with Ctrl + C.

Putting the Whole Journey Together

Every one of these steps builds directly on the last — installation makes the node command available, the REPL builds confidence with small pieces of JavaScript, running a file confirms the full execution flow works end to end, and the server ties it all together into something genuinely running and reachable from a browser.

Final Takeaway

Getting Node.js running for the first time is really just five small, concrete confirmations, one after another: it’s installed, it responds to commands, it can evaluate JavaScript interactively, it can run a file from start to finish, and it can keep a process alive to actually serve real requests. None of these steps are complicated in isolation — but walking through all of them, in order, on your own machine, is what turns “Node.js” from an abstract name into something you’ve genuinely built and run yourself.

Frequently Asked Questions

Do I need to install anything besides Node.js to follow this guide?

> No — everything here (the REPL, running a script, the Hello World server) uses only what comes bundled with a standard Node.js installation. No external frameworks or packages are required.

Why does my terminal seem “stuck” after starting the server?

> That’s expected — the server process stays running, actively listening for incoming requests, rather than finishing and returning control back to your terminal prompt. Press Ctrl + C to stop it when you're done.

What’s the difference between running node and node app.js?

> Running node alone opens the interactive REPL, for typing and evaluating JavaScript line by line. Running node app.js executes an entire file from start to finish, non-interactively, the way a real program typically runs.

Can I use a port other than 3000 for the server?

> Yes — 3000 is just a common convention for local development, not a requirement. Any available port number (typically above 1024, to avoid needing special permissions) works the same way — just update PORT in the code and the URL you visit in the browser to match.

Originally published by Mr Madhukar

Read the complete article on Medium with full formatting & reader responses.