await-to-js is a lightweight zero-dependency utility that wraps a Promise and returns an array with either an error or the resolved value, enabling a Go-like error handling pattern in async/await functions. The current stable version is 3.0.0, with a stable release cadence. It ships TypeScript definitions. Differentiators: extremely simple API, tree-shakable, no external dependencies. It is commonly used in Node.js and browser environments to avoid try-catch blocks and improve code readability when handling promise rejections.
npm install await-to-jsNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates basic usage of await-to-js to handle a resolved promise, checking for error first.
Update comparisons: if (err !== null) should become if (err !== undefined).
Use import to from 'await-to-js' or const to = require('await-to-js').default;Ensure your promises reject with Error objects for consistent error handling.
Upgrade to latest version and use default import. For old code, use import { to } from 'await-to-js'.Use const to = require('await-to-js').default;Change import { to } from 'await-to-js' to import to from 'await-to-js'Install the package: npm install await-to-js. Ensure tsconfig.json includes 'node' in moduleResolution or set 'esModuleInterop': true.
No dependency data recorded yet.