Skip to main content

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 npm install.

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

FeatureDescription
Pre-installedNo install needed, they're part of Node.js
Load fasterNode.js caches them in memory, no disk access
Written in C++/JSMost are wrappers around system APIs
Names with no pathImported with no ./ or ../
Used via require() or importWork in both CommonJS and ESM

3. Examples of core modules

CategoryModulePurpose
FilesystemfsWorking with files and folders (reading, writing, streams)
Networkinghttp, https, net, dnsBuilding servers, TCP/HTTP, DNS lookups
Path handlingpathManipulating paths (join, resolve, basename, etc.)
System and OSosSystem info, CPU, memory, platform
UtilitiesutilHelper functions (promisify, types, inherits)
TimerstimersAccess to setTimeout, setInterval, setImmediate
StreamsstreamWorking with read/write streams
BuffersbufferWorking with binary data (including files and networking)
CryptographycryptoHashing, encryption, key generation
Processesprocess, child_processAccess to the current process and spawning children
ModulesmoduleWorking with Node.js's module system
CompressionzlibCompressing and decompressing data (gzip, deflate, etc.)
URL and queriesurl, querystringParsing URLs, handling query strings
Diagnosticsv8, perf_hooks, inspectorWorking with V8, profiling, debugging

4. Usage examples

The fs module

Working with files:

javascript
import { readFileSync } from 'fs'; const text = readFileSync('./hello.txt', 'utf8'); console.log(text);

The http module

Building a simple HTTP server:

javascript
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:

javascript
import path from 'path'; const fullPath = path.join('users', 'tim', 'notes.txt'); console.log(fullPath); // users/tim/notes.txt

The os module

Getting system information:

javascript
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:

javascript
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:

javascript
import { builtinModules } from 'module'; console.log(builtinModules);

It prints an array of every built-in module, for example:

javascript
[ '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:

javascript
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:

javascript
require('fs');

Node.js:

  1. Checks whether the module is in the core list;
  2. If it is, loads it from memory (a C++ binding), skipping the filesystem and node_modules entirely.

That's why require('fs') is faster than require('./fs.js').

8. Core modules vs external ones

ComparisonCore moduleExternal (npm)
SourceBuilt into Node.jsInstalled via npm install
StorageInside the Node.js binaryIn node_modules
LoadingNo disk accessRead from the filesystem
UpdatesOnly with a Node.js versionUpdated independently
Examplefs, path, cryptoexpress, 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') or import 'name'.

9. The most commonly used core modules

ModulePurpose
fsWorking with files
pathPath manipulation
http / httpsBuilding servers
osSystem information
eventsCreating and handling events
cryptoHashing and encryption
child_processSpawning child processes
streamData streams
urlWorking with URLs
utilUtility functions (promisify, inherits)

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.