Home Coding & Scripting Getting Started with Node.js: Setup and Hello World

Getting Started with Node.js: Setup and Hello World

310
0

utside the browser and even build your own web servers. In this post, we’ll walk through setting up Node.js on your computer and writing your very first “Hello World” program.


🛠 Step 1: Install Node.js

There are two main ways to install Node.js:

  • Quick Start (Beginner Friendly): Download the official Node.js LTS installer. This is the fastest way to get started.
  • Developer Way (Recommended): Use Node Version Manager (nvm), which lets you install and switch between multiple versions of Node.js — something you’ll need as you grow into a developer.

👉 In this post, we’ll keep it simple and use the official installer so you can jump straight into writing code. If you want to set things up like a pro from the beginning, check out my full guide here: Node Version Manager (nvm): A Developer’s Guide to Installing and Managing Node.js Versions.

Now, let’s install Node.js using the quick start method:

  1. Go to the Node.js download page.
  2. Download the latest LTS (Long Term Support) version (recommended for beginners).
  3. Run the installer. If you see an option to also install extra tools (like Python and Visual Studio via Chocolatey), select it — it saves time later.

👉 To check if it worked, open your terminal/command prompt and type:

node -v
npm -v

You should see the installed versions of Node.js and npm (the Node.js package manager).


📂 Step 2: Create a Project Folder

Let’s create a folder to keep your code organized. In your terminal:

mkdir my-first-node-app
cd my-first-node-app

👩‍💻 Step 3: Write Your First Program

Inside your folder, create a file named app.js. Add this code:

// app.js
console.log("Hello, World from Node.js!");

Now run it:

node app.js

✅ You should see this output in your terminal:

Hello, World from Node.js!

🌐 Step 4: Create a Simple Web Server

Let’s go a step further and make Node.js serve a web page. Replace the code in app.js with this:

// app.js
const http = require("http");

// Create a server
const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader("Content-Type", "text/plain");
  res.end("Hello, World from Node.js Server!\n");
});

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

Run it again:

node app.js

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

🎉 You’ll see your first Node.js web page!


🧠 How It Works

  • console.log prints messages to your terminal.
  • http.createServer creates a simple server.
  • server.listen(3000) tells it to listen on port 3000.

✅ Key Takeaway

With just a few steps, you’ve:

  • Installed Node.js
  • Written a basic program
  • Built a simple web server

This is the foundation of Node.js development. From here, you can start exploring frameworks like Express.js or even full-stack solutions like Next.js to make server building even easier.

Previous articleSetup Node.js on Windows Using nvm
Next articleWhat is Node.js? A Beginner’s Guide
Heartin Kanikathottu
As a seasoned Cloud and Security Architect, I’ve led transformative initiatives in key roles, including Vice President at Morgan Stanley, Principal Architect at Societe Generale, and Tech Lead & Cloud Security Architect at VMware, among others. I’m also an internationally published author with multiple books available on platforms like Amazon and O'Reilly. Notably, one of my books was recognized as the 8th best cloud computing book of all time in 2020, reflecting the impact of my contributions to the field. With over 15 professional certifications from providers such as Microsoft (Azure), Amazon (AWS), Oracle (Java), Pivotal (Spring), and IBM, I bring a wealth of expertise to my work. Academically, I hold dual Master’s degrees in Cloud Computing and Data Analytics. I’m passionate about sharing knowledge and mentoring others, which is why I actively speak at global technical forums such as Tech Opportunities Fest at Platform Calgary, Google's Kubernetes Meetup, Java User Group, Elasticsearch Meetup, and the Agile India Conference.

LEAVE A REPLY

Please enter your comment!
Please enter your name here