Node.js Get Started

Node.js Tutorial

Node.js – Get Started

What • Why • Installation • First App • How It Works • Next Steps

Node.js lets you run JavaScript outside the browser.
You can build fast servers, APIs, real-time apps, and scalable backend systems using only JavaScript.

 One-line idea

Node.js = JavaScript on the server


1️⃣ What is Node.js?

Node.js is a JavaScript runtime environment built on V8 JavaScript Engine.

It allows JavaScript to run on:

  • Servers

  • PCs

  • APIs

  • Backend systems

Before Node.js → JavaScript worked only in browsers
After Node.js → JavaScript works everywhere


2️⃣ Why Use Node.js?

Very fast (non-blocking, event-driven)
✔ Same language for frontend & backend
✔ Handles thousands of requests easily
✔ Huge ecosystem via npm
✔ Used by Netflix, Uber, PayPal, LinkedIn


3️⃣ How Node.js Works (Simple Explanation)

Node.js uses:
  • Single Thread

  • Non-blocking I/O

  • Event Loop

 Instead of waiting for one task to finish, Node.js keeps working and handles results asynchronously.


4️⃣ Install Node.js (Step-by-Step)

 Step 1: Download

Visit 👉 https://nodejs.org
Choose: LTS (Recommended for beginners)

 Step 2: Install

  • Windows → Next → Next → Install

  • macOS.pkg file

  • Linux → Package manager

  Step 3: Verify Installation

node -v
npm -v

 If versions appear → Installation successful


5️⃣ Your First Node.js Program

Create a file: app.js

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

Run:

node app.js

Output

Hello, Node.js!

6️⃣ Create a Simple Web Server


 

👉 Open browser: http://localhost:3000


7️⃣ What is npm?

npm (Node Package Manager)
Used to install libraries & tools.

Examples:

npm install express
npm install nodemon

 npm has 1M+ packages


8️⃣ Popular Node.js Use Cases

✔ REST APIs

✔ Web servers
✔ Real-time chat apps
✔ Streaming platforms
✔ Microservices
✔ IoT backends


9️⃣ Node.js vs Other Backend Languages

FeatureNode.jsPHP / Java
LanguageJavaScriptPHP / Java
SpeedVery FastModerate
ScalabilityHighMedium
Real-time AppsExcellentHarder

🔟 Basic Folder Structure

project/
│── node_modules/
│── app.js
│── package.json
  • node_modules → Installed packages

  • package.json → Project info & dependencies


 Running JS without node filename.js
 Confusing Node.js with browser JavaScript


Common Beginner Mistakes

❌ Forgetting to install Node.js❌ Writing blocking code (heavy loops, sleep)


Final Summary

✔ Node.js runs JavaScript on the server
✔ Fast, scalable & event-driven
✔ Uses npm for packages
✔ Ideal for APIs & real-time apps
Must-know skill for modern web developers

You may also like...