Skip to content
Justice Tech School

util Module

util.promisify, format, inspect and types help with everyday work.

Example
const util = require("util");
const sleep = util.promisify(setTimeout);
sleep(10).then(() => console.log("slept"));
console.log(util.format("%s is %d", "Ada", 30));
console.log(util.inspect({ a: { b: { c: 1 } } }, { depth: 0 }));

Result

Ada is 30
{ a: [Object] }
slept

Exercise

Callback to promise.

util.(fn)

Quiz Test

What does promisify turn into a promise?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.