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

Learning web development in public. Writing simple, real-world explanations about web development concepts. Helping beginners understand why things work, not just how.
Starting with Node.js for the first time can feel confusing, but the setup is actually very simple. In this guide, you will go step by step from installing Node.js to running your first server.
1. Installing Node.js
To begin, you need to install Node.js on your system.
Go to the official website: https://nodejs.org
Download the LTS (Long Term Support) version (recommended for beginners)
Run the installer and follow the default steps
The installation also includes npm (Node Package Manager), which is used to install libraries.
2. Checking Installation Using Terminal
After installing, you should verify that Node.js is correctly installed.
Open your terminal or command prompt and run:
node -v
This will show the installed Node.js version.
Next, check npm:
npm -v
If both commands return versions, your setup is successful.
3. Understanding Node REPL
Node.js provides a built-in environment called REPL.
REPL stands for:
Read
Evaluate
Print
Loop
It allows you to run JavaScript code directly in the terminal.
Start REPL:
node
Now you can type JavaScript:
2 + 3
Output:
5
You can also try:
console.log("Hello from REPL");
To exit REPL:
.exit
REPL is useful for quick testing and learning.
4. Creating Your First JavaScript File
Now let’s create your first Node.js program.
Create a new folder (for example:
node-app)Inside the folder, create a file named:
app.js
- Add the following code:
console.log("Hello, Node.js!");
5. Running Script Using Node Command
To run your file, open terminal in the same folder and execute:
node app.js
Output:
Hello, Node.js!
This is your first Node.js program running successfully.
6. Writing a Hello World Server
Now let’s create a simple server using Node.js.
Update your app.js file:
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 port 3000");
});
What this code does:
Imports the built-in
httpmoduleCreates a server
Sends a response when a request comes
Starts listening on port 3000
Run the server:
node app.js
Now open your browser and go to:
http://localhost:3000
You will see:
Hello World from Node.js Server
Final Understanding
You installed Node.js and npm on your system
Verified the installation using terminal commands
Learned how to use the REPL environment for quick experimentation
Created your first JavaScript file and executed it using Node
Built a basic HTTP server and understood how it responds to requests
Learned how Node.js runs outside the browser and can be used to create backend applications
Summary
By completing these steps, you have built a strong foundation in Node.js. You now understand how to set up the environment, run JavaScript outside the browser, and create a working server. This is the first step toward building real-world applications such as APIs, web servers, and full-stack projects. From here, you can start exploring frameworks like Express.js, working with databases, and building scalable backend systems.



