{"library":"pn","title":"Promisified Node.js Standard Library","description":"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.","language":"javascript","status":"abandoned","last_verified":"Sun Apr 19","install":{"commands":["npm install pn"],"cli":null},"imports":["import fs from 'pn/fs';","import child_process from 'pn/child_process';","require('pn/_promise')(MyPromise);"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import fs from 'pn/fs';\nimport child_process from 'pn/child_process';\n\nasync function runExample() {\n  console.log('--- File Write Example ---');\n  try {\n    await fs.writeFile('foo.txt', 'Hello pn!', 'utf-8');\n    console.log('File \"foo.txt\" written successfully via Promise.');\n  } catch (err) {\n    console.error('Error writing file:', err);\n  }\n\n  // Callback usage still works\n  fs.writeFile('bar.txt', 'Hello with callback!', 'utf-8', (err) => {\n    if (err) console.error('Error writing file (callback):', err);\n    else console.log('File \"bar.txt\" written successfully via callback.');\n  });\n\n  console.log('\\n--- Child Process Example ---');\n  try {\n    const cp = child_process.execFile('node', ['-e', 'console.log(\"Hello from child!\"); console.error(\"Error from child!\");']);\n    console.log(`Child process started with PID: ${cp.pid}`);\n    const result = await cp.promise;\n    console.log('Child process finished.');\n    console.log('Stdout:', result.stdout.trim());\n    console.log('Stderr:', result.stderr.trim());\n  } catch (err) {\n    console.error('Error executing child process:', err);\n  }\n}\n\nrunExample();","lang":"javascript","description":"Demonstrates writing a file using a Promise and a callback, and executing a child process with Promise-based handling of stdout/stderr.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}