01

Day 1: Introduction to Node.js

Chapter 1 • Beginner

25 min

Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine. It allows you to run JavaScript on the server side, outside of web browsers.

What is Node.js?

Node.js is a platform that allows JavaScript to be executed on the server side. It uses an event-driven, non-blocking I/O model that makes it lightweight and efficient.

Key Features of Node.js:

  • Fast execution using Google's V8 engine
  • Asynchronous programming with non-blocking I/O
  • Single-threaded but highly scalable
  • Large ecosystem of packages (npm)
  • Cross-platform compatibility
  • Built-in modules for file system, HTTP, and more

Why Use Node.js?

Node.js is perfect for building scalable network applications, APIs, real-time applications, and microservices. It's particularly popular for web development, IoT applications, and data streaming.

Node.js Architecture:

Node.js has a unique architecture with several layers:

  • JavaScript Application Layer
  • Node.js API Layer (fs, http, crypto, etc)
  • V8 Engine (JavaScript Runtime)
  • libuv (Event Loop)

Getting Started:

To start using Node.js, you need to install it on your system. Node.js comes with npm (Node Package Manager) which helps you manage dependencies and packages.

Hands-on Examples

Hello World Program

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

// Basic arithmetic
const a = 10;
const b = 20;
console.log('Sum:', a + b);
console.log('Product:', a * b);

// Working with strings
const firstName = 'John';
const lastName = 'Doe';
const fullName = firstName + ' ' + lastName;
console.log('Full Name:', fullName);

This is a basic Node.js program that demonstrates console output, variables, and string concatenation. Run this with: node hello.js