Back to Modules

Node.js Tutorial

Master Node.js fundamentals with our comprehensive tutorial. Learn through examples and hands-on practice.

Video Tutorial

Introduction to Node.js

Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine that allows you to run JavaScript on the server side.

Examples:

// Basic Node.js program
const name = 'Node.js';
const year = 2009;

// Working with variables
const greeting = `Hello from ${name}!`;
const info = `${name} was created in ${year}`;

// Simple calculation
const sum = 10 + 20;

// Node.js provides process object
const version = process.version;
const platform = process.platform;

A simple Node.js program with variables and process object

Working with Arrays and Objects

Node.js uses JavaScript, so you can work with arrays, objects, and all JavaScript features.

Examples:

// Working with Arrays
const fruits = ['Apple', 'Banana', 'Orange'];
const firstFruit = fruits[0];

// Array methods
fruits.push('Mango');
const fruitCount = fruits.length;

// Working with Objects
const person = {
  name: 'John',
  age: 30,
  city: 'New York'
};

// Accessing object properties
const personName = person.name;
const personAge = person.age;

// Object methods
const personInfo = `${person.name} is ${person.age} years old`;

Working with arrays and objects in Node.js

Functions and Async Programming

Node.js excels at handling asynchronous operations using callbacks, promises, and async/await.

Examples:

// Regular function
function greet(name) {
  return `Hello, ${name}!`;
}

const greeting = greet('World');

// Arrow function
const add = (a, b) => a + b;
const result = add(5, 3);

// Async function with Promise
function delay(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}

async function asyncExample() {
  await delay(100);
  return 'Done';
}

// Using async function
asyncExample().then(result => {
  // Handle result
});

Functions and async/await in Node.js