Setting Up Your First Node.js Application: A Complete Step-by-Step Guide for Beginners
By a Backend Developer with 10+ Years of Experience
Hello everyone! After more than a decade building scalable backend systems, APIs, and real-time applications, I still remember how empowering it felt to run my first Node.js script. Node.js revolutionized server-side JavaScript and remains one of the best platforms for developers who want speed, a massive ecosystem, and the ability to use one language end-to-end.
In this beginner-friendly guide, we’ll go from zero to running a basic server — no frameworks, no shortcuts. We’ll also cover essential npm practices and how to start thinking about configuration and security from day one.
1. Installing Node.js (OS-Neutral)
Node.js is available for Windows, macOS, and Linux.
Recommended way (easiest for most developers):
- Visit the official website: https://nodejs.org
- Download the LTS version (Long Term Support). This is the most stable choice for production and learning.
- Run the installer.
Alternative methods (if you prefer):
- macOS/Linux: Use a version manager like nvm (Node Version Manager). It allows you to switch Node versions easily.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
nvm install --lts
-
Windows: Use Winget (
winget install OpenJS.NodeJS.LTS) or Chocolatey.
After installation, restart your terminal/command prompt.
2. Verifying the Installation
Open your terminal (Terminal on macOS/Linux, Command Prompt or PowerShell on Windows) and run:
node --version
npm --version
You should see version numbers (e.g., v20.18.x and 10.x.x). If these commands work, you’re ready!
Pro Tip: Always use the LTS version in production. Current LTS as of 2026 is in the 20.x or 22.x series.
3. Understanding Node.js REPL
Before writing files, let’s explore the REPL (Read-Eval-Print-Loop). It’s an interactive shell where you can execute JavaScript code instantly — perfect for testing ideas.
What is REPL?
- Read: Takes your input
- Eval: Executes it
- Print: Shows the result
- Loop: Waits for the next input
To start the REPL, type:
node
You’ll see a > prompt. Try these:
> console.log("Hello from Node.js REPL!")
Hello from Node.js REPL!
undefined
> 5 + 7
12
> const name = "Grok"; name.toUpperCase()
'GROK'
Exit the REPL with:
-
.exit - or press
Ctrl + C(twice on some systems)
REPL is excellent for quick experiments but not suitable for real applications.
4. Creating Your First JavaScript File
Create a new folder for your project:
mkdir my-first-node-app
cd my-first-node-app
Inside this folder, create a file named app.js (or index.js).
Using your favorite code editor (VS Code recommended), add this code:
// app.js
console.log("Hello World! My first Node.js application is running 🚀");
console.log("Current date and time:", new Date().toLocaleString());
5. Running the Script
In the terminal, from your project folder, execute:
node app.js
Expected output:
Hello World! My first Node.js application is running 🚀
Current date and time: 5/9/2026, 10:xx AM
Diagram: Script → Node Runtime → Output
[Your .js File]
↓
Node.js Runtime (V8 Engine + Libuv)
↓
Executes JavaScript
↓
Console / Network / File System
↓
Output / Response
This flow is the heart of Node.js. Your JavaScript runs on Google’s V8 engine, while Libuv handles asynchronous I/O.
6. Writing a Simple Hello World HTTP Server (No Frameworks)
Create a new file server.js:
const http = require('http');
const server = http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello World! This is my first Node.js server.\n');
});
const PORT = 3000;
server.listen(PORT, () => {
console.log(`Server running at http://localhost:${PORT}/`);
});
Run it:
node server.js
Open your browser and visit http://localhost:3000. You should see the message.
Press Ctrl + C to stop the server.
Congratulations! You now have a working HTTP server using only Node.js core modules.
Working with npm — The Heart of Node.js Ecosystem
Every serious Node.js project starts with:
npm init -y
This creates a package.json file — the manifest of your project.
Key sections in package.json:
-
scripts(custom commands) dependenciesdevDependencies-
engines(Node version requirement)
Essential npm Packages for Configuration & Security
As a backend developer, I never start a real project without these foundations:
Configuration Management
-
dotenv— Load environment variables from.envfile (never commit secrets!)
npm install dotenv
-
configorconvict— For structured, validated configuration.
Security Essentials
-
helmet— Sets secure HTTP headers (even if you use plain http initially) -
express-rate-limit— Prevent brute force and DDoS (when you adopt Express) -
cors— Control cross-origin requests -
bcryptorargon2— Password hashing -
jsonwebtoken(jsonwebtoken) — For JWT authentication -
express-validatororjoi— Input validation
Basic security starter commands:
npm install dotenv helmet
Example .env:
PORT=3000
NODE_ENV=production
JWT_SECRET=your-super-secret-key-here
Security Checklist (from day one):
- Never hardcode secrets
- Validate all user input
- Use
helmetfor headers - Implement rate limiting
- Keep dependencies updated (
npm audit) - Run with least privileges
- Use tools like
npm auditand Snyk regularly
Next Steps After This Tutorial
- Learn the built-in modules:
fs,path,events,crypto - Move to Express.js (the de-facto minimal framework)
- Explore TypeScript for larger applications
- Add proper logging (
winstonorpino) - Containerize with Docker
Final Thoughts
Node.js has incredible performance and a thriving ecosystem. Starting simple (as we did here) builds strong fundamentals. The real power comes when you combine core Node.js knowledge with battle-tested packages and security-first mindset.
I’ve shipped many production systems following exactly this path — starting from console.log to millions of requests per day.
What’s next? Try building a simple REST API that reads/writes a JSON file. Then share your first project in the comments!
Happy coding! If you found this helpful, leave a like, follow for more backend-focused content, and feel free to ask questions below.
Top comments (0)