Setting Up Your First Node.js Application Step-by-Step
Your First Real Server (This Is Where It Gets Fun)
Hi, I’m Abdul Samad. A web development learner and tech enthusiast. I write about what I learn, share practical coding tips, and publish in-depth blogs on programming and modern web development.
Check out my full collection of blogs on Hashnode: https://abdulsamad30.hashnode.dev/
Connect with me on X for quick updates and insights: @abdul_sama60108
Getting Started with Node.js: Installation, REPL, and Your First Server
Every developer remembers their first time running code outside of a browser and thinking wait, this actually works? That moment when JavaScript stops being a browser thing and becomes something you can run anywhere is genuinely exciting. This post is going to walk you through exactly that journey from installing Node.js on your machine to writing your very first server. No frameworks, no shortcuts, just the real fundamentals.
Let's get you set up.
Installing Node.js
Before anything else, you need Node.js on your machine. The good news is the installation process is straightforward regardless of whether you're on Windows, macOS, or Linux.
Head over to the official Node.js website at nodejs.org. You'll see two version options:
LTS (Long Term Support) stable, recommended for most developers, especially beginners
Current latest features, but less stable
Go with LTS. It's the reliable choice and what most tutorials and production environments use.
Download the installer for your operating system and follow the steps. The installer handles everything Node.js itself, npm (Node Package Manager), and the necessary PATH configurations so your terminal can find the node command.
Once the installer finishes, don't close it and assume everything worked. The next step is actually confirming it.
Checking Installation Using the Terminal
After installation, open your terminal Command Prompt or PowerShell on Windows, Terminal on macOS or Linux and verify that Node.js installed correctly.
Run these two commands:
node --version
npm --version
Expected Output:
v20.11.0
10.2.4
Your version numbers might differ depending on when you're reading this, but as long as you see version numbers and not errors, you're good. If you see something like command not found, it usually means the PATH wasn't set correctly try restarting your terminal or reinstalling Node.js.
Two commands, two confirmations. Node.js is ready.
Understanding the Node REPL
Now here's something that surprises a lot of beginners you can run JavaScript directly in your terminal without creating a file. This is called the REPL.
REPL stands for Read-Eval-Print Loop. It's an interactive environment that:
Reads what you type
Evaluates it as JavaScript
Prints the result
Loops back and waits for your next input
It's like a live conversation with Node.js. You type something, it responds immediately. It's incredibly useful for quickly testing a piece of logic without the overhead of creating and running a file.
To start the REPL, simply type node in your terminal and press Enter:
node
You'll see a > prompt appear, which means Node.js is listening and ready.
> 2 + 2
4
> "Hello".toUpperCase()
'HELLO'
> let name = "Node.js"
undefined
> `Welcome to ${name}`
'Welcome to Node.js'
Expected Output:
4
'HELLO'
undefined
'Welcome to Node.js'
Notice that assigning a variable with let returns undefined that's normal. The assignment itself doesn't produce a value, so REPL prints undefined. But on the next line, when you use that variable, it works perfectly.
To exit the REPL, press Ctrl + C twice, or type .exit and press Enter.
The REPL is great for quick experiments, but for anything real, you need a proper file.
Creating Your First JavaScript File
Writing code in the REPL is temporary the moment you exit, everything is gone. For real work, you write your code in a .js file and run it with Node.js.
Create a new file called app.js you can do this in any code editor like VS Code, or even a plain text editor. The name doesn't have to be app.js, but it's a clean, conventional starting point.
Inside app.js, write this:
// app.js
const message = "Node.js is running!";
const currentTime = new Date().toLocaleTimeString();
console.log(message);
console.log("Current time:", currentTime);
console.log("This is JavaScript running on the server.");
This is pure JavaScript. No browser, no HTML, no document just logic and output. You're using Date() to grab the current time and console.log() to print results. Simple, clean, and completely valid on the server side.
Running a Script Using the Node Command
Now that your file exists, running it is one simple command. In your terminal, navigate to the folder where app.js lives and run:
node app.js
Expected Output:
Node.js is running!
Current time: 10:45:23 AM
This is JavaScript running on the server.
That's it. node followed by the filename Node.js reads the file, executes it from top to bottom, prints the output, and exits. Clean and straightforward.
A few things worth knowing:
You need to be in the correct directory when running this command. Use
cd your-folder-nameto navigate there first.Node.js executes the file completely and then stops. It doesn't stay running unless your code explicitly keeps it alive like a server does.
Any errors in your code will print to the terminal with a description of what went wrong and which line caused it.
Writing a Hello World Server
You've installed Node.js, explored the REPL, created a file, and run it. The natural next step is writing something that feels like a real server because that's what Node.js is actually built for.
Node.js comes with a built-in http module that lets you create a web server without installing anything extra. No Express, no frameworks just Node.js doing what it does natively.
Create a new file called server.js and write the following:
// server.js
const http = require('http');
const server = http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello, World! Welcome to my Node.js server.\\n');
});
server.listen(3000, function () {
console.log('Server is running at <http://localhost:3000>');
console.log('Press Ctrl + C to stop the server.');
});
Let's walk through what's happening here line by line:
require('http')loads Node's built-in HTTP modulehttp.createServer()creates a server that accepts a function. That function runs every time someone makes a request.reqthe incoming request (what the user is asking for)resthe response (what you send back)res.writeHead(200, ...)sends a status code 200 (meaning success) and sets the content typeres.end(...)sends the actual response body and closes the connectionserver.listen(3000, ...)tells the server to start listening on port 3000
Now run it:
node server.js
Expected Output (in terminal):
Server is running at <http://localhost:3000>
Press Ctrl + C to stop the server.
Open your browser and visit http://localhost:3000. You'll see:
Hello, World! Welcome to my Node.js server.
Notice that unlike app.js, this server doesn't exit after running. It stays alive, listening for requests. Every time you refresh the browser, the server processes a new request and sends back the same response. That's the server staying alive through the event loop it keeps running until you manually stop it with Ctrl + C.
Wrapping Up
You've covered a lot of real ground here. Let's do a quick recap of the journey:
Installed Node.js from nodejs.org using the LTS version stable and beginner-friendly
Verified the installation using
node --versionandnpm --versionin the terminalExplored the REPL Node's interactive environment where you can run JavaScript instantly without a file
Created a JavaScript file and wrote real code that runs on the server
Executed that file using the
node filename.jscommandBuilt a Hello World HTTP server using Node's built-in
httpmodule no frameworks needed
What makes this foundation so valuable is that every more advanced Node.js concept you'll learn later routing, middleware, databases, APIs builds on exactly this. The http module, the node command, the idea of a server that stays alive and responds to requests it all starts here.
You've written your first server. That's not a small thing.
FIN ✌️




