Suggest an editImprove this articleRefine the answer for “What is a "core module" in Node.js?”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)A **core module** ships with Node.js by default (`fs`, `http`, `path`, `os`, `crypto`, ...) and needs no npm install; it's baked into the Node.js binary itself, so it loads faster than file-based or npm modules. **Key point:** `require('fs')` is faster than `require('./fs.js')`, because a core module comes straight from memory, bypassing the filesystem.Shown above the full answer for quick recall.Answer (EN)Image## 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 | 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: ```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 | 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')` or `import '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`) |For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.