🚀 Getting Started with Node.js: A Beginner’s Guide to Building Your First App

Dhruvi ShahDhruvi Shah
5 min read

If you're new to backend development or curious about JavaScript beyond the browser, Node.js is the perfect place to start. It's fast, lightweight, and powers everything from APIs to real-time apps like chat systems and dashboards.

In this guide, you'll learn:

  • ✅ What Node.js is

  • 🔧 How to install it

  • 💻 How to build your very first Node.js app

Let’s dive in!


🔍 What is Node.js?

Node.js is a runtime that lets you run JavaScript code outside the browser — like on a server.

💡 Think of it as using JavaScript to write backend code that can talk to databases, send emails, or power your website behind the scenes.

It’s built on Chrome’s V8 engine, which makes it incredibly fast and efficient.

⚡ Why Use Node.js?

Here’s why developers love Node.js:

  • 🧠 Uses JavaScript everywhere (frontend + backend)

  • 🌀 Asynchronous and non-blocking — fast performance

  • 📦 Huge package ecosystem with npm (Node Package Manager)

  • 🌐 Great for APIs, real-time apps, dashboards, and more


🛠️ Setting Up Your Development Environment

Before diving into writing code, let’s set up the tools you need to build with Node.js. This includes installing Node.js itself, verifying the installation, and choosing the right code editor.

📥 Installing Node.js

There are two common ways to install Node.js:

  • Direct download from the official website (easy)

  • Using a version manager like nvm (recommended for developers)

👉 Option 1: Download from Node.js Website

Head over to 👉 nodejs.org
Download
the LTS (Long-Term Support) version for your system.

After installing, open your terminal and run:

node -v
npm -v

If you see version numbers for both, you’re good to go!

👉 Option 2: Install via nvm (Node Version Manager)

If you’re using macOS or Linux, this is the best option. It allows you to switch between Node.js versions easily.

Install nvm:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

Then restart your terminal and install Node.js:

nvm install --lts
nvm use --lts

Verify with:

node -v

💡 Use nvm use <version> to switch between different Node.js versions later.

💻 Test Your Installation (REPL Mode)

To quickly check if Node.js is working, run:

node

This opens the Node REPL — an interactive shell.

Try typing:

console.log("Hello, Node.js!");

To exit, type .exit or press Ctrl + C twice.


🧰 Set Up a Code Editor

A good editor makes coding smoother.
The best choice for Node.js development is:

Visual Studio Code (VS Code)

  • Lightweight and fast

  • Integrated terminal and Git

  • Tons of useful extensions

  • 🔧 ESLint – for clean, consistent code

  • 🧹 Prettier – for auto-formatting

  • 📦 Node.js Extension Pack – all-in-one toolkit

Now your development environment is ready!
Up next, we’ll start writing your first real Node.js app. 👨‍💻


🧩 Understanding Node.js Modules and npm

As you begin building apps with Node.js, you’ll quickly come across modules and npm — two core concepts that power the Node ecosystem.

Let’s break them down.

📦 What are Modules in Node.js?

Modules are reusable blocks of code. Instead of writing everything in one file, you can split functionality into multiple modules and import or require them when needed.

🔄 Think of modules like LEGO blocks — each does one thing, and together they build your app.

🔧 Built-in Modules

Node.js comes with several core modules out of the box. No installation required.

Some popular ones:

  • fs – File system operations

  • http – Build web servers

  • path – Handle file paths

  • os – System info

📦 What is npm?

npm (Node Package Manager) is a tool that comes with Node.js. It lets you:

  • Install packages (libraries)

  • Manage project dependencies

  • Share your own packages

Every project with npm uses a package.json file to manage its metadata and dependencies.

🚀 Installing npm Packages

To install a package, use:

npm install package-name

Example: Install the popular lodash utility library

npm install http

📁 Managing Dependencies

All installed packages go into a node_modules folder.

To view all installed dependencies:

npm list

To remove a package:

npm uninstall package-name

⚠️ Don’t forget to add a .gitignore file and exclude node_modules when sharing your code.

📄 Bonus Tip: Initialize npm

When starting a new Node.js project, run:

npm init -y

This creates a basic package.json file for you. You can then install and manage packages cleanly.


👨‍💻 Creating Your First Node.js App

Let’s build a simple “Hello World” web server using Node.js.

Step 1: Create a Project

Open your terminal and run:

mkdir my-first-node-app
cd my-first-node-app
npm init -y

Create a new file called app.js.

Step 2: Add This Code

// app.js

const http = require('http');

// Create a server
const server = http.createServer((req, res) => {
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.end('Hello, Node.js!');
});

// Start the server
server.listen(3000, () => {
  console.log('Server running at http://localhost:3000/');
});

Step 3: Run Your App

In the terminal:

node app.js

Now, open your browser and go to:
👉 http://localhost:3000

You’ll see:
Hello, Node.js!

🎉 Boom! You’ve just created your first Node.js server.


🧠 What’s Next?

From here, you can explore:

  • Building REST APIs with Express.js

  • Connecting to databases like MongoDB

  • Creating real-time apps with WebSockets


✅ Conclusion

Congratulations on building your first Node.js app! 🎉

Node.js opens up a whole new world for JavaScript developers — now you can create full-stack apps using one language.

Keep learning, experiment freely, and break things — that’s how real developers grow. 💪

💬 Let’s Connect!

Did this post help you get started with Node.js?
Got questions or ideas for what I should write next?

Leave a comment below or share this with someone starting their dev journey.

0
Subscribe to my newsletter

Read articles from Dhruvi Shah directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Dhruvi Shah
Dhruvi Shah