Getting Started with Node.js: A Beginner’s Guide

Node.js has revolutionized the way we think about JavaScript, taking it out of the browser and onto the server. If you've been wanting to build backend applications using the language you already know and love, you're in the right place.
Here is a step-by-step guide to setting up your very first Node.js environment and running your first server.
Installing Node.js
Before you can run JavaScript on your machine, you need the Node.js runtime.
How to install: Visit the official Node.js website.
Recommendation: Download the LTS (Long Term Support) version. It is the most stable version and is recommended for most users.
Platform Neutrality: Whether you are on Windows, macOS or Linux, the installer will handle the environment variables for you, making
nodeaccessible from your command line.
Verifying the Installation
Once the installation is complete, you need to ensure your system recognizes Node.js. Open your terminal (Command Prompt, PowerShell, or Terminal) and type the following commands:
To check the Node version:
node -vTo check the npm (Node Package Manager) version:
npm -v
If you see version numbers (e.g., v20.x.x), you are ready to go!
Understanding the Node REPL
Before we write a file, let's look at the REPL.
REPL stands for Read-Eval-Print-Loop. It is an interactive shell that takes your JavaScript code, evaluates it, and prints the result immediately. It's a fantastic place to test small logic snippets without creating a file.
How to use it:
Type
nodein your terminal and hit Enter.You'll see a prompt (usually
>).Type
2+2and hit Enter. It will output4.Type
.exitor pressCtrl + Ctwice to leave.
Creating and Running Your First JS File
While the REPL is fun, real applications live in files.
Create a file: Open your favorite text editor (like VS Code) and create a new file named
app.js.Add logic: Write a simple line of code:
console.log("Node.js is running successfully!");
- Run the script: Go back to your terminal, navigate to the folder where you saved the file, and run:
node app.js
You should see your message printed directly in the terminal.
Writing a "Hello World" Server
To truly understand Node's power, let's build a basic web server. We will use the built-in http module, so no external frameworks (like Express) are needed yet.
Create a file named server.js and follow these steps:
Import the HTTP module: This allows Node to transfer data over the HyperText Transfer Protocol.
Create the server: Use the
createServermethod which takes a function with a request (req) and a response (res).Set the headers and content: Tell the browser the request was successful (Status 200) and send "Hello World".
Listen on a port: Tell the server to stay active on a specific port (e.g., 3000).
Conceptual Implementation
const http = require('http');
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World from my first Node server!');
});
server.listen(3000, '127.0.0.1', () => {
console.log('Server running at http://127.0.0.1:3000/');
});
Execution
Run node server.js in your terminal. You will see the console log. Now, open your web browser and go to http://localhost:3000. You’ve just successfully launched your first backend server!
Key Takeaways
Node.js allows JavaScript to run on your local machine/server.
The REPL is perfect for quick experimentation.
The
nodecommand is your primary tool for executing.jsfiles.The
httpmodule is the foundation of web networking in Node.js.
By mastering these basics, you've built the foundation necessary to dive into more complex topics like file systems, asynchronous programming, and eventually, full-scale APIs.


