DEV Community

Cover image for Setting Up Your First Node.js Application Step-by-Step
Ritam Saha
Ritam Saha

Posted on

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

Introduction

Imagine you're a developer staring at a blank screen, buzzing with ideas for your dream web app, but you're stuck at basic square one—no runtime, no environment, no idea where to start how to do. Sound familiar? But not anymore...

Node.js changes everything for us. What seemed impossible one day, but NodeJS says "not anymore broo". Node is the powerhouse JavaScript runtime that lets you run JS on the server side, powering giants like Netflix and LinkedIn. Whether you're a CS student building your portfolio or a hobbyist dipping into full-stack dev, this guide walks you through every step to build your first Node.js app. No frameworks—just pure, hands-on setup. By the end, you'll have a "Hello World" server humming on your machine. Let's dive in.


Installing NodeJS: Setup with Platform Notes

NodeJS installation is straightforward and consistent across operating systems. The golden rule? Use the official NodeSource binaries or your system's package manager for the latest LTS (Long-Term Support) version. This ensures stability for production-like projects.

Step 1: Download from the Official Site (Universal Starting Point)

Head to nodejs.org. Grab the LTS version:

  • Windows: Download the .msi installer. Run it as administrator mode in powershell, follow the wizard (enable "Add to PATH" checkbox), and restart your terminal.
  • macOS: Get the .pkg installer. Double-click, enter your password, and let it install. Homebrew users: brew install node.
  • Linux (Ubuntu/Debian): Use NodeSource repo for freshness:
  curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
  sudo apt-get install -ca nodejs
Enter fullscreen mode Exit fullscreen mode
  • Linux (Fedora/RHEL): sudo dnf install nodejs (or use NodeSource similarly).
  • NixOS or Nix Environments: Add to configuration.nix:
  environment.systemPackages = with pkgs; [ nodejs ];
Enter fullscreen mode Exit fullscreen mode

Then sudo nixos-rebuild switch.

Pro tip: Avoid downloading from third-party sites to dodge malware. Installation takes 2-5 minutes max.

Node Installation


Verifying Your Installation

Fire up your terminal (Command Prompt/PowerShell on Windows, Terminal on macOS/Linux/NixOS). Type:

node --version
npm --version
Enter fullscreen mode Exit fullscreen mode

You should see something like v24.14.0 for node, not exactly this, I mean in this structure. And for npm you might see like 11.9.0. npm gets download automatically with node, npm is nothing but node package manager (though if you go to npm's official site, they call it as npm package manager), this is for to install any other packages/dependancies that will help building your site and it comes with node's download by default.

node version check

Node is live. This command confirms the runtime is ready to execute JavaScript outside the browser.


Demystifying the Node.js REPL: Your Interactive Playground

Before we code, let's unpack REPL. REPL stands for Read-Eval-Print Loop—Node's built-in interactive shell for testing code snippets on the fly. It's like a JavaScript console in your terminal: type code, hit Enter, see results instantly. Perfect for experimenting without files.

Launch it:

node
Enter fullscreen mode Exit fullscreen mode

Your prompt changes to >. Try:

> console.log('Hello, Node!')
> 2 + 2
> let x = 5; x * 3
Enter fullscreen mode Exit fullscreen mode

Exit with Ctrl+C twice or .exit.

REPL

REPL shines for quick prototypes—think debugging math logic or testing string methods before building full scripts.


Creating and Running Your First JavaScript File

Time to level up from REPL. Create a project folder:

mkdir my-first-node-app
cd my-first-node-app
Enter fullscreen mode Exit fullscreen mode

Use your editor (VS Code recommended code . in addressbar, if installed). Make hello.js (touch hello.js in terminal):

console.log('Hello from my first Node.js script!');
console.log('Node version:', process.version);
Enter fullscreen mode Exit fullscreen mode

Save it. Run with:

node hello.js
Enter fullscreen mode Exit fullscreen mode

First execution output (yours should match):

Hello from my first Node.js script!
Node version: v20.12.2
Enter fullscreen mode Exit fullscreen mode

Magic! Node reads the file, compiles it just-in-time, executes in the V8 engine (Chrome's JS heart), and prints to stdout. No browser needed.


Building a Hello World Server: Your First Server

NodeJS excels at servers via its http module (built-in, no npm needed). Create server.js:

const http = require('node:http'); //CommonJS type
//http is built-in module of NodeJS

const server = http.createServer((req, res) => {
  //creating basic HTTP server using createServer()
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World from Node.js Server!\n'); //sending basic text
});

const port = 3000; //You can use this within .env, but for that you have to install dotenv from npm
server.listen(port, 'localhost', () => {
  // By this you are enabling server's continuous listening for any request
  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

Output: Server running at http://localhost:3000/. Open that URL in your browser, "Hello World from Node.js Server!" greets you.

Stop with Ctrl+C. This introduces Node's event-driven model: the server loops, handling requests non-blockingly.


Wrapping Up: From Zero to Node Hero

You've just conquered Node.js setup—from install to a live server—without frameworks clouding the waters. This foundation unlocks full-stack magic: pair it with Express later, deploy to Vercel (my go-to for portfolio projects), and watch your GitHub shine. As a third-year CS student juggling Java backends and Node experiments, I live this daily—it's empowering.

What's your first project idea? Drop it in the comments!

Top comments (0)