Util Module in Node.js

From the Node.js Core Modules cheat sheet ยท Utilities & Advanced ยท verified Jul 2026

Util Module

Utility functions for debugging and promisification

javascript
const util = require('util')
const fs = require('fs')

// Promisify callback-based functions
const readFile = util.promisify(fs.readFile)
const data = await readFile('file.txt', 'utf8')

// Format strings (like printf)
const msg = util.format('%s:%d', 'Server', 8080)
// 'Server:8080'

// Deep inspect objects
const obj = { a: 1, b: { c: 2, d: [3, 4] } }
console.log(util.inspect(obj, { 
  showHidden: true, 
  depth: null, 
  colors: true 
}))
๐Ÿ’ก promisify() converts callbacks to promises
๐Ÿ“Œ util.inspect() is great for debugging
โšก TextEncoder/Decoder for UTF-8 conversion
๐ŸŸข Essential for modernizing callback code
๐Ÿ”— Related: console.dir() for simple inspection
utilitiesdebugging

Continue with Node.js Core Modules

Save the full cheat sheet or work through every related task.

More Node.js tasks

Back to the full Node.js Core Modules cheat sheet