3.1 Introduction to Node.js – The Power of JavaScript on the Server

Table of Contents

Hi Codders! πŸ‘‹
I’m Vikas Sankhla, your tech guide and founder of the Web Codder YouTube channel.
Today we’re exploring a super cool topic: Node.js. πŸš€

Node.js is like giving JavaScript a superhero cape so it can work on the server side too!


🌍 What Is Node.js?

Let’s start with the basics.

Node.js is a tool that lets you run JavaScript on the server. ✨

  • Before Node.js, JavaScript could only run in browsers like Chrome or Firefox.
  • With Node.js, JavaScript can now run on your computer’s server too.

πŸ› οΈ How Is It Different from Traditional Server Languages?

Languages like:

Traditional LanguagesWhat They Do
PHPBackend scripting
JavaFull-stack programming
PythonWeb + AI + backend programming

But Node.js is special because:

  • πŸŒ€ It’s JavaScript (so you only need to know one language for both frontend and backend).
  • ⚑ It’s fast because it uses an event-driven, non-blocking model (more on that soon!).
  • 🌱 It’s lightweight and scalable.

πŸ”Ž Understanding the Node.js Runtime Environment

You can think of Node.js like a kitchen. 🍳

  • The ingredients = JavaScript code.
  • The kitchen (Node.js) = where the code runs and gets cooked.

πŸ’‘ Node.js uses Google Chrome’s V8 Engine to run JavaScript outside the browser.


πŸ”„ What’s Inside Node.js?

  • 🧱 Core Modules – Built-in tools like fs (file system), http, etc.
  • πŸšͺ APIs – To access files, servers, databases.
  • 🌐 V8 Engine – Converts JS code into machine code FAST.

βš™οΈ The Magic: Event-Driven, Non-Blocking I/O

Okay, this sounds tricky πŸ˜… but let’s make it super simple.

πŸ” Imagine:

  • You’re at a burger shop.
  • You place your order.
  • Instead of making you wait at the counter until your burger is ready, they take your order and move on to the next customer.
  • When your burger is ready, they call your name. πŸ“£

That’s Node.js! βœ…

It doesn’t wait for one task to finish before moving to the next. This is called:

ConceptMeaning
Event-drivenListens for events (like “order ready!”)
Non-blocking I/ODoesn’t block other tasks while waiting

Ff22Bcdb A829 4446 92E9 5Efcbcf2683F
3.1 Introduction To Node.js – The Power Of Javascript On The Server 3


πŸš€ Setting Up a Simple Node.js App

Let’s build something small but awesome. πŸ‘‡

1️⃣ Install Node.js


2️⃣ Check if It’s Installed

Open your terminal/command prompt:

bashCopyEditnode -v
npm -v

βœ… You should see version numbers like:

CopyEditv18.16.0
9.6.7

3️⃣ Create a Basic App

  • Make a folder: my-first-node
  • Inside, create a file: app.js

Add this code:

jsCopyEditconsole.log("Hello from Node.js! πŸ‘‹");

Now run it:

bashCopyEditnode app.js

Boom πŸ’₯ – You just ran JavaScript outside the browser!


🌱 Using npm – Node’s Superpower

What’s npm?

npm = Node Package Manager
It helps you:

  • πŸ“¦ Install ready-made code (called packages)
  • πŸš€ Share your own code

Example: Let’s install a popular package chalk to color text.

bashCopyEditnpm init -y
npm install chalk

In your app.js:

jsCopyEditconst chalk = require('chalk');
console.log(chalk.green('Hello in green! 🌿'));

Run:

bashCopyEditnode app.js

πŸŽ‰ Your text is now green!


Screen Shot 2022 04 12 At 09.16.47
3.1 Introduction To Node.js – The Power Of Javascript On The Server 4

🧱 Understanding Modules in Node.js

Node.js has a modular structure. Think of modules like LEGO blocks. 🧩

  • Built-in Modules: Like fs (file system), http
  • Your Own Modules: Split your code into different files and connect them

Example of a custom module:

greet.js:

jsCopyEditfunction sayHi(name) {
  console.log(`Hello, ${name}!`);
}

module.exports = sayHi;

app.js:

jsCopyEditconst greet = require('./greet');
greet('Web Codder');

🚩 Quick Recap

FeatureWhat It Does
Node.jsRuns JavaScript outside the browser
Event-drivenListens to and handles events
Non-blocking I/ODoesn’t wait; moves to next task while one is running
npmInstalls and manages packages
ModulesHelps break code into reusable parts

πŸ’‘ Why Use Node.js?

  • πŸ”₯ One language everywhere (JS for frontend + backend)
  • πŸš€ Fast and scalable
  • 🌍 Huge community & packages
  • πŸ’Ό Great for APIs, real-time apps (chat, gaming)

🎯 Conclusion

Node.js is like supercharging your JavaScript skills πŸš€ so you can build full-fledged web apps all by yourself.


πŸš€ Keep Learning with Web Codder!

Share the Post:
Picture of Web Codder

Web Codder

Vikas Sankhla is a seasoned Full Stack Developer with over 7 years of experience in web development. He is the founder of Web Codder, a platform dedicated to providing comprehensive web development tutorials and resources. Vikas specializes in the MERN stack (MongoDB, Express.js, React.js, Node.js) and has been instrumental in mentoring aspiring developers through his online courses and content. His commitment to simplifying complex web technologies has made him a respected figure in the developer community.

Related Posts