Loading

Quipoin Menu

Learn • Practice • Grow

node-js / Built-in Modules Recap
tutorial

Built-in Modules Recap

Now that you understand modules deeply, let's recap all the built-in modules we've covered so far. Think of this as your handy reference guide – whenever you need to work with files, paths, OS, or events, you'll know exactly which module to use.

Core Modules at a Glance

ModulePurposeCommon Use
`fs`File SystemRead/write files, directories
`path`File pathsJoin, resolve, parse paths
`os`Operating SystemSystem info, CPUs, memory
`events`Event handlingCreate custom events
`http`HTTP servers/clientsCreate web servers
`url`URL parsingParse and format URLs
`util`UtilitiesPromisify, formatting
`crypto`CryptographyHashing, encryption

Think of built-in modules as the standard library of Node.js – they're always available, well-tested, and cover the most common tasks you'll encounter.

1. File System (fs)
const fs = require('fs');
const fsPromises = require('fs').promises;

<!-- Read file -->
fs.readFileSync('file.txt', 'utf8');

<!-- Write file -->
fs.writeFileSync('output.txt', 'Hello');

<!-- Check if file exists -->
fs.existsSync('file.txt');

2. Path Module
const path = require('path');

<!-- Join paths -->
const fullPath = path.join(__dirname, 'folder', 'file.txt');

<!-- Get file extension -->
const ext = path.extname('image.jpg'); <!-- .jpg -->

<!-- Parse path -->
const parsed = path.parse('/users/john/file.txt');

3. OS Module
const os = require('os');

console.log(os.platform()); <!-- 'win32', 'darwin', 'linux' -->
console.log(os.cpus().length); <!-- CPU cores -->
console.log(os.freemem()); <!-- Free memory in bytes -->

4. Events Module
const EventEmitter = require('events');
const emitter = new EventEmitter();

emitter.on('greet', (name) => {
  console.log(`Hello, ${name}`);
});

emitter.emit('greet', 'World');

5. HTTP Module
const http = require('http');

const server = http.createServer((req, res) => {
  res.writeHead(200);
  res.end('Hello World');
});

server.listen(3000);

6. URL Module
const url = require('url');

const myUrl = new URL('https://example.com/path?name=john');
console.log(myUrl.pathname); <!-- /path -->
console.log(myUrl.searchParams.get('name')); <!-- john -->

7. Util Module
const util = require('util');

<!-- Promisify a callback-based function -->
const fs = require('fs');
const readFilePromise = util.promisify(fs.readFile);

8. Crypto Module
const crypto = require('crypto');

<!-- Create a hash -->
const hash = crypto.createHash('sha256').update('password').digest('hex');

Two Minute Drill

  • Built-in modules are always available – no npm install needed.
  • `fs` for files, `path` for paths, `os` for system info.
  • `events` for custom events, `http` for web servers.
  • `url` and `querystring` for URL handling.
  • `util` provides helpful utilities like `promisify`.
  • `crypto` for hashing and encryption.

Need more clarification?

Drop us an email at career@quipoinfotech.com