Performance: Built-in modules overview
This affects the initial load time and runtime performance by controlling how much code is loaded and executed from Node.js core modules.
Jump into concepts and practice - no test required
import { readFileSync } from 'fs'; readFileSync('file.txt', 'utf8');
import fsExtra from 'fs-extra'; fsExtra.readFileSync('file.txt', 'utf8');
| Pattern | Module Size Impact | Load Time | Memory Usage | Verdict |
|---|---|---|---|---|
| Using external package for core functionality | Adds 20-50kb+ | Slower startup | Higher memory | [X] Bad |
| Using Node.js built-in module | No extra size | Fast startup | Lower memory | [OK] Good |
fs module in Node.js using ES modules?node: prefix with ES module import syntax for built-in modules.import fs from 'node:fs'; which is correct. import fs from 'fs'; misses the prefix, B uses CommonJS syntax, C incorrectly destructures.import + node: prefix for built-in modules [OK]import os from 'node:os'; console.log(os.platform());
import path from 'node:path';
const fullPath = path.join('/home', 'user', 123);
console.log(fullPath);fs module with promises. Which code snippet correctly imports and uses it?