Beginner Backend

Node.js Basics

Runtime environment, modules, npm, and async programming.

JavaScript on the Server

Node.js is a JavaScript runtime built on Chrome's V8 engine, enabling JavaScript to run outside the browser for server-side development.

Core Concepts

  • Event Loop: Non-blocking I/O that handles concurrent operations efficiently
  • Modules: CommonJS (require) and ES Modules (import/export)
  • npm: Package manager with the largest ecosystem of open source libraries
  • package.json: Project manifest defining dependencies and scripts

Async Patterns

  • Callbacks: Traditional async pattern (callback hell)
  • Promises: Chainable async operations
  • async/await: Synchronous-looking async code
// Reading a file asynchronously
const fs = require('fs/promises');

async function readConfig() {
  const data = await fs.readFile('config.json', 'utf-8');
  return JSON.parse(data);
}

Built-in Modules

  • fs - File system operations
  • path - Path manipulation
  • http - HTTP server and client
  • crypto - Cryptographic functions
  • events - Event emitter pattern