In this article, we review promisify method. You will learn:
What is util.promisify?
What is Roo-Code?
Usage example.
What is util.promisify?
Util is a NodeJS API. It has a lot of method defined. Check the util page. We are interested in promisify.
Promisify
Promisify takes a function following the common error-first callback style, i.e. taking an (err, value) => ... callback as the last argument, and returns a version that returns promises.
Below is an example picked from the docs:
import { promisify } from 'node:util';
import { stat } from 'node:fs';
const promisifiedStat = promisify(stat);
promisifiedStat('.').then((stats) => {
// Do something with `stats`
}).catch((error) => {
// Handle the error.
});
Learn more about promisify.
What is Roo-Code?
Roo Code gives you a whole dev team of AI agents in your code editor.
What Can Roo Code Do For YOU?
Generate Code from natural language descriptions and specs
Adapt with Modes: Code, Architect, Ask, Debug, and Custom Modes
Refactor & Debug existing code
Write & Update documentation
Answer Questions about your codebase
Automate repetitive tasks
Utilize MCP Servers
Modes
Roo Code adapts to how you work:
Code Mode: everyday coding, edits, and file ops
Architect Mode: plan systems, specs, and migrations
Ask Mode: fast answers, explanations, and docs
Debug Mode: trace issues, add logs, isolate root causes
Custom Modes: build specialized modes for your team or workflow
Learn more about Roo-Code.
Usage example
In the Roo-Code codebase, there is a file, worktree-service.ts. It has promisify imported as shown below, at the top of the file:
import { promisify } from "util"
How is this used? Roo-Code is making two methods return as a promise as shown below:
import { exec, execFile } from "child_process"
import { promisify } from "util"
...
const execAsync = promisify(exec)
const execFileAsync = promisify(execFile)
and then this promisified functions are used in the WorktreeService class as shown below:
/**
* Service for managing git worktrees.
* All methods are platform-agnostic and don't depend on VSCode APIs.
*/
export class WorktreeService {
/**
* Check if git is installed on the system
*/
async checkGitInstalled(): Promise<boolean> {
try {
await execAsync("git --version")
return true
} catch {
return false
}
}
...
About me:
Hey, my name is ramunarasinga. Email: ramunarasinga@gmail.com
Tired of AI slop?
I spent 3+ years studying OSS codebases and wrote 350+ articles on what makes them production-grade. I built
Codebase architecture skills, inspired by best OSS projects.

Top comments (0)