Course contentsShow
← JavaScript
Lesson 1443 of 2,72331. ModulesFree lesson

Requiring Built-in Modules

Access Node.js core modules like fs, path, and http using require without a path.

Requiring Built-in Modules

You'll learn how to access Node.js's powerful built-in modules without needing to install anything extra.

What Are Built-in Modules?

Node.js comes with a collection of core modules already installed and ready to use — no npm install needed. These modules provide essential functionality like working with files (fs), manipulating paths (path), creating web servers (http), and much more. They're part of every Node.js installation.

Accessing Built-in Modules

To use a built-in module, you require() it by name — without a path. This is different from requiring your own files, where you'd use ./ or ../:

const fs = require('fs');
const path = require('path');
const http = require('http');

Notice there's no ./ or file path. Node.js knows these are core modules and finds them automatically.

Why No Path?

Think of built-in modules like utilities in a toolbox that's always attached to Node.js itself. When you write require('fs'), Node.js checks its internal registry first. If it finds a core module with that name, it loads it immediately. Only if no built-in module matches does Node.js start looking in node_modules or local files.

Common Built-in Modules

  • fs — file system operations (read/write files)
  • path — handle file paths across different operating systems
  • http — create web servers and make HTTP requests
  • os — operating system information
  • util — utility functions
const os = require('os');
// Now you can use os.platform(), os.homedir(), etc.

Key Takeaway: Built-in Node.js modules are required by name alone (no path), giving you immediate access to core functionality without installation.