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

If you're starting your journey in backend development, installing Node.js is your first step. In this guide, you'll learn how to install Node.js on any operating system.
What is Node.js : Node.js is free , open source and cross platform that allow us to run javaScript outside the browser.
Node.js was originally created by Ryan Dahl in 2009. Before Node.js javascript is used in client-side(frontend) only. But with Node.js we run javaScript on server-side. We make full stack website using a single language.
Runtime, Not a Language: Node.js is not a programming language or a framework; it is an environment that executes JavaScript using Google Chrome's V8 engine.
Installing Node.js :
Before installing Node.js, make sure:
You have a system (Windows, macOS, or Linux)
Internet connection is available
Go to official website of Node.js download page.
You can open download page. I will automatically identify your operating system.
Download LTS (Long Term Support) version (it is stable)
Current version (less stable)
Windows :
Download
.msiinstallerDouble-click the download .msi file
Click Next → Next → Install
Finish installation
Verify Installation :
You can use command Prompt or powerShell to verify Node.js installation .
Run this command to verify node installation.
node -v (or node --version)
If installed it will return version number like v24.3.0.
Verify npm (node package manager) installation :
npm -v (or npm --version)
This should return a version number like 10.5.0.
macOS
Download
.pkginstallerOpen the file
Follow installation steps
Verify Installation :
Use terminal application of Mac to verify Node.js installation.
Run this command to verify Node.js.
node -v
If installed correctly, it will return a version number (e.g., v24.15.0).
Verify npm installation :
npm -v
Since npm is bundled with node it should also return version a number.
Linux :
Best way to install Node.js for linux through nvm . It allow developers to switch between multiple version without sudo permissions.
Install nvm : Run the following command in your terminal to download and run the install script:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.4/install.sh | bash
Reload your shell : close and reopen your shell or run.
source ~/.bashrc
Install Node.js: Use nvm to install the latest Long Term Support (LTS) version:
nvm install --lts
Verify Installation :
node -v
npm -v
Installation and verification process complete for all operating systems.
Understanding Node REPL :
The Node.js (Read-Eval-Print Loop) is interactive terminal environment to execute javascript code line by line without creating a file. I read your input evaluate it and show output . I allow multiple line code snippets useful for debugging , testing snippets . Also provide command history.
Use Node.js REPL (Best for Quick Testing) :
Start REPL :
node
Now you can write JavaScript directly:
> 2 + 2
4
> console.log("Hello world")
Hello world
Run Code Directly from Terminal (-e flag)
You can execute code inline:
node -e "console.log('Hello from Node')"
Useful for one liners and quick script.
Creating first JS file :
Create a file with .js extension:
index.js
You can create it using vs code or using terminal.
touch index.js
Running script using node command :
To fun your javascript file check index.js exits.
write a console.log() in your empty file.
console.log("Running script using Node");
Command to run the file :
node index.js
You can see output in terminal.
Running script using Node
Let's try to create a sever using Node.js :
A minimal server requirement is importing http module and calling createServer.
const http = require('http');
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello, World!\n');
});
const PORT = 3000;
server.listen(PORT, () => {
console.log(`Server running at http://localhost:${PORT}/`);
});
what is http module : The HTTP module is a built-in Node.js library that allow use to create servers and make networking request without installing third party libraries.
http.createServer(): It returns a new instance of server and takes call back that run every time when request arrives.
req (request): It contains incoming data form client like headers and url etc.
res (response) : The response what server to send back to to client after receiving a request .
res.end() : It is used to finish the response and send it to client.
Summary :
In this blog, we explored what is Node.js . We learned how to install Node.js on our system and verify the installation correctly.
We also explored the Node.js REPL, which helps in quickly testing JavaScript code without creating files.
Finally, we created our first server using the Node.js HTTP module.




