Chapter 1: Node.js Get Started

Node.js” guide — written as if I’m sitting next to you with a coffee, showing you everything on my screen step by step, explaining why we do each thing, and warning about the most common beginner traps.

Let’s really begin from zero — no skipping steps.

Step 0 – Mindset before we touch the keyboard

Most people get stuck in the first 2–3 days because of these wrong expectations:

  • “I will write backend code like frontend React code” → no, structure and thinking are quite different
  • “I need to learn everything at once (Express + Mongo + JWT + React + Docker…)” → biggest mistake
  • “Node.js is very hard” → actually very easy to start, very hard to master well

Good first-week goal (2026):

  • Run a server
  • Understand folders & files
  • Make GET + POST requests
  • See your own data coming back
  • Feel “I can actually build something real”

That’s what we’re going to do today — very cleanly.

Step 1 – Install Node.js the smart way (2026 recommendation)

Do NOT just click “download LTS” from nodejs.org if you plan to code seriously.

Best way = use a version manager → you can switch versions in 10 seconds later.

Windows / macOS / Linux – use nvm (most popular)

macOS & Linux

Bash

Close terminal completely and open a new one, then:

Bash

Windows (recommended: nvm-windows)

https://github.com/coreybutler/nvm-windows/releases → download & install latest .exe

Then in PowerShell or Command Prompt:

Bash

Verify installation

Bash

You now have Node.js and npm (the package manager).

Step 2 – Create your first real project folder

Bash

Now initialize it properly:

Bash

This creates package.json — think of it as the identity card of your project.

Open the folder in VS Code (or any editor you like):

Bash

Step 3 – Install only what we need right now

We’ll use Express — the most popular & beginner-friendly web framework for Node.js.

Bash

Also install a very helpful development tool:

Bash

nodemon = auto-restart server when you save a file → huge time saver.

Step 4 – First working server (modern style – 2026)

Create file: server.js

JavaScript

Important change for modern Node.js

Open package.json and add this line:

JSON

This tells Node.js: “please use modern import syntax instead of old require”

Step 5 – Add start scripts (very important habit)

Update package.json → scripts section:

JSON

Now you can run:

Bash

You should see:

text

Open browser: http://localhost:4000

You did it! 🎉

Step 6 – Add your first POST endpoint (real API feeling)

Add this code before the app.listen(…) line:

JavaScript

Now test it (you can use browser extensions, Postman, or terminal):

Using curl (terminal)

Bash

You should get back something like:

JSON

Congratulations — you just built your first real API endpoint!

Step 7 – Summary table – What you already have

File / Command Purpose Why important?
package.json Project identity & scripts Heart of every Node.js project
“type”: “module” Allows modern import syntax Future-proof, cleaner code
npm run dev Auto-restart with nodemon Saves hours of frustration
express.json() middleware Parses incoming JSON Lets you read req.body easily
res.json() Sends JSON response Most common way to answer API requests
res.status(201) Sets proper HTTP status code Good API practice
GET / Home / health check Always good to have
POST /users Create resource First taste of real backend work

Step 8 – Next 3–5 days recommended path (very realistic)

Day 1 (today): → What you just did — basic server + GET + POST

Day 2: → Query parameters (?id=123&sort=desc) → Route parameters (/users/:id) → Basic input validation (if/else or later Zod)

Day 3: → Separate routes into folders → Create routes/users.js → Learn router from Express

Day 4: → Connect to a real database (MongoDB Atlas free or PostgreSQL local)

Day 5: → Learn how to handle errors globally → Add simple .env file + dotenv

Which direction would you like to go next?

Just tell me one thing you want to do right now:

  1. Add query parameters and route parameters with examples
  2. Move routes to separate files (cleaner structure)
  3. Validate data properly (using Zod – very modern & clean)
  4. Connect to MongoDB (easiest database for beginners)
  5. Handle errors in a professional way
  6. Use .env file for secrets & configuration
  7. Create GET /users and fake in-memory database
  8. Understand what middleware really is with examples

Pick one number (or write what you want) — I’ll continue exactly from your current code with very detailed steps.

Happy coding — you’re already further than most beginners after one session! 🚀

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *