DEV Community

Bhupesh Chandra Joshi
Bhupesh Chandra Joshi

Posted on

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

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):

  1. Visit the official website: https://nodejs.org
  2. Download the LTS version (Long Term Support). This is the most stable choice for production and learning.
  3. 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
Enter fullscreen mode Exit fullscreen mode
  • 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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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'
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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());
Enter fullscreen mode Exit fullscreen mode

5. Running the Script

In the terminal, from your project folder, execute:

node app.js
Enter fullscreen mode Exit fullscreen mode

Expected output:

Hello World! My first Node.js application is running 🚀
Current date and time: 5/9/2026, 10:xx AM
Enter fullscreen mode Exit fullscreen mode

Diagram: Script → Node Runtime → Output

[Your .js File] 
       ↓
Node.js Runtime (V8 Engine + Libuv)
       ↓
   Executes JavaScript
       ↓
   Console / Network / File System
       ↓
      Output / Response
Enter fullscreen mode Exit fullscreen mode

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}/`);
});
Enter fullscreen mode Exit fullscreen mode

Run it:

node server.js
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

This creates a package.json file — the manifest of your project.

Key sections in package.json:

  • scripts (custom commands)
  • dependencies
  • devDependencies
  • 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 .env file (never commit secrets!)
  npm install dotenv
Enter fullscreen mode Exit fullscreen mode
  • config or convict — 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
  • bcrypt or argon2 — Password hashing
  • jsonwebtoken (jsonwebtoken) — For JWT authentication
  • express-validator or joi — Input validation

Basic security starter commands:

npm install dotenv helmet
Enter fullscreen mode Exit fullscreen mode

Example .env:

PORT=3000
NODE_ENV=production
JWT_SECRET=your-super-secret-key-here
Enter fullscreen mode Exit fullscreen mode

Security Checklist (from day one):

  1. Never hardcode secrets
  2. Validate all user input
  3. Use helmet for headers
  4. Implement rate limiting
  5. Keep dependencies updated (npm audit)
  6. Run with least privileges
  7. Use tools like npm audit and Snyk regularly

Next Steps After This Tutorial

  1. Learn the built-in modules: fs, path, events, crypto
  2. Move to Express.js (the de-facto minimal framework)
  3. Explore TypeScript for larger applications
  4. Add proper logging (winston or pino)
  5. 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)