pn is a JavaScript library that provides Promise-returning wrappers for the Node.js standard library functions that traditionally use callbacks. Released in its current form (v1.1.0) in 2016, it aimed to bridge the gap before native `async/await` and `util.promisify` were standard in Node.js. It operates by returning a Promise only if no callback is supplied, allowing existing callback-based code to function without modification. The library handles various 'odd cases' in Node.js APIs, such as functions that return multiple values via callback or those that return an object while also taking a callback. Its release cadence is effectively inactive, with the last update in 2016. While functional, modern Node.js environments (v8+ for `util.promisify`, v7.6+ for `async/await`) have native alternatives that are generally preferred.
npm install pnVerified import paths — ran on the pinned version, not inferred.
Demonstrates writing a file using a Promise and a callback, and executing a child process with Promise-based handling of stdout/stderr.
Use `require('pn/crypto').randomBytesSync()` or `require('pn/crypto').pseudoRandomBytesSync()` for synchronous operations, or `await require('pn/crypto').randomBytes()` for asynchronous promise-based usage.Access resolved values as properties of the returned object (e.g., `result.hostname`, `result.service`) instead of expecting multiple arguments in a `.then()` handler.
Access the Promise via `returnedObject.promise` to await its resolution, for example, `const cp = child_process.execFile(...); await cp.promise;`.
Ensure a Promise polyfill is loaded by `require('es6-shim');` or similar at the entry point of your application if targeting environments without native Promises.Load a Promise polyfill like `es6-shim` or `core-js` before `pn`: `require('es6-shim'); var fs = require('pn/fs');`For synchronous operations, use the `pn` specific synchronous variants: `require('pn/crypto').randomBytesSync(...)` or `require('pn/crypto').pseudoRandomBytesSync(...)`.Always chain a `.catch(err => { /* handle error */ })` to Promise chains or wrap `await` calls in `try...catch` blocks to handle potential errors.No dependency data recorded yet.