@antithrow/node
v1.0.0
Published
Non-throwing wrappers around Node.js APIs using antithrow Result types
Maintainers
Readme
Why
Node.js APIs like fs/promises communicate failure by throwing. @antithrow/node re-exports them as thin wrappers that return Result instead, so error handling is type-safe and composable out of the box.
import { readFile, writeFile } from "@antithrow/node/fs/promises";
const data = await readFile("input.txt", "utf-8")
.mapErr(() => new AppError("failed to read file"));
await writeFile("output.txt", data.toUpperCase())
.mapErr(() => new AppError("failed to write file"));Installation
bun add @antithrow/nodeantithrow is a required peer/runtime dependency and will be installed automatically.
Usage
fs/promises
Wraps fs/promises API with Result for type-safe file operations.
import { readFile, writeFile, mkdir } from "@antithrow/node/fs/promises";
import { JSON } from "@antithrow/std";
// Read a file
const content = await readFile("./config.json", "utf-8")
.andThen((text) => JSON.parse(text));
// Write a file
await writeFile("./output.txt", "Hello, World!");
// Create directories
await mkdir("./nested/path", { recursive: true });os
Wraps node:os functions that can throw with Settled results for type-safe system info access.
import { homedir, hostname, userInfo } from "@antithrow/node/os";
// Get home directory
const home = homedir();
// Get hostname
const host = hostname();
// Get user info
const user = userInfo();