What is a "core module" in Node.js?
1. Definition
A core module (built-in module) ships as part of Node.js by default and needs no
npminstall.
These modules are baked into Node.js itself, written in C++ and JavaScript, and give access to operating-system features, the filesystem, networking, and so on.
2. Main characteristics
| Feature | Description |
|---|---|
| Pre-installed | No install needed, they're part of Node.js |
| Load faster | Node.js caches them in memory, no disk access |
| Written in C++/JS | Most are wrappers around system APIs |
| Names with no path | Imported with no ./ or ../ |
Used via require() or import | Work in both CommonJS and ESM |
3. Examples of core modules
| Category | Module | Purpose |
|---|---|---|
| Filesystem | fs | Working with files and folders (reading, writing, streams) |
| Networking | http, https, net, dns | Building servers, TCP/HTTP, DNS lookups |
| Path handling | path | Manipulating paths (join, resolve, basename, etc.) |
| System and OS | os | System info, CPU, memory, platform |
| Utilities | util | Helper functions (promisify, types, inherits) |
| Timers | timers | Access to setTimeout, setInterval, setImmediate |
| Streams | stream | Working with read/write streams |
| Buffers | buffer | Working with binary data (including files and networking) |
| Cryptography | crypto | Hashing, encryption, key generation |
| Processes | process, child_process | Access to the current process and spawning children |
| Modules | module | Working with Node.js's module system |
| Compression | zlib | Compressing and decompressing data (gzip, deflate, etc.) |
| URL and queries | url, querystring | Parsing URLs, handling query strings |
| Diagnostics | v8, perf_hooks, inspector | Working with V8, profiling, debugging |
4. Usage examples
The fs module
Working with files:
import { readFileSync } from 'fs';
const text = readFileSync('./hello.txt', 'utf8');
console.log(text);The http module
Building a simple HTTP server:
import http from 'http';
const server = http.createServer((req, res) => {
res.end('Hello from Node.js!');
});
server.listen(3000);The path module
Working with paths:
import path from 'path';
const fullPath = path.join('users', 'tim', 'notes.txt');
console.log(fullPath); // users/tim/notes.txtThe os module
Getting system information:
import os from 'os';
console.log('Platform:', os.platform());
console.log('CPU cores:', os.cpus().length);
console.log('Free memory:', os.freemem());The crypto module
Creating a SHA256 hash:
import crypto from 'crypto';
const hash = crypto.createHash('sha256').update('password123').digest('hex');
console.log(hash);5. How to tell if a module is core
Node.js provides a built-in method:
import { builtinModules } from 'module';
console.log(builtinModules);It prints an array of every built-in module, for example:
[
'fs', 'path', 'os', 'http', 'crypto', 'stream', 'events',
'zlib', 'url', 'dns', 'net', 'child_process', ...
]6. Using core modules with ESM
In ESM (with "type": "module"), core modules are loaded like this:
import fs from 'fs';
import path from 'path';
import { createServer } from 'http';No ./, just the module name itself.
7. Why core modules are faster
When you call:
require('fs');Node.js:
- Checks whether the module is in the core list;
- If it is, loads it from memory (a C++ binding),
skipping the filesystem and
node_modulesentirely.
That's why require('fs') is faster than require('./fs.js').
8. Core modules vs external ones
| Comparison | Core module | External (npm) |
|---|---|---|
| Source | Built into Node.js | Installed via npm install |
| Storage | Inside the Node.js binary | In node_modules |
| Loading | No disk access | Read from the filesystem |
| Updates | Only with a Node.js version | Updated independently |
| Example | fs, path, crypto | express, lodash, axios |
In one sentence
Core modules are the modules built into Node.js that give low-level access to OS features (files, networking, processes, streams, cryptography, and so on), available with no install via
require('name')orimport 'name'.
9. The most commonly used core modules
| Module | Purpose |
|---|---|
fs | Working with files |
path | Path manipulation |
http / https | Building servers |
os | System information |
events | Creating and handling events |
crypto | Hashing and encryption |
child_process | Spawning child processes |
stream | Data streams |
url | Working with URLs |
util | Utility functions (promisify, inherits) |
Short Answer
Interview readyA concise answer to help you respond confidently on this topic during an interview.