{"id":13563502,"url":"https://github.com/nodegit/promisify-node","last_synced_at":"2025-04-05T04:14:01.598Z","repository":{"id":15950059,"uuid":"18692565","full_name":"nodegit/promisify-node","owner":"nodegit","description":"Wrap Node-callback functions to return Promises.","archived":false,"fork":false,"pushed_at":"2019-04-02T21:01:10.000Z","size":33,"stargazers_count":149,"open_issues_count":9,"forks_count":23,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-31T05:01:59.946Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nodegit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-04-12T00:25:06.000Z","updated_at":"2024-12-08T09:33:26.000Z","dependencies_parsed_at":"2022-09-05T17:00:42.847Z","dependency_job_id":null,"html_url":"https://github.com/nodegit/promisify-node","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodegit%2Fpromisify-node","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodegit%2Fpromisify-node/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodegit%2Fpromisify-node/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodegit%2Fpromisify-node/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nodegit","download_url":"https://codeload.github.com/nodegit/promisify-node/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247284951,"owners_count":20913704,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T13:01:20.010Z","updated_at":"2025-04-05T04:14:01.580Z","avatar_url":"https://github.com/nodegit.png","language":"JavaScript","readme":"Promisify Node\n--------------\n\n**Stable: 0.5.0** \n\n[![Build\nStatus](https://travis-ci.org/nodegit/promisify-node.png?branch=master)](https://travis-ci.org/nodegit/promisify-node)\n\nMaintained by Tim Branyen [@tbranyen](http://twitter.com/tbranyen).\n\nWraps Node modules, functions, and methods written in the Node-callback style\nto return Promises.\n\n### Install ###\n\n``` bash\nnpm install promisify-node\n```\n\n### Examples ###\n\nWrap entire Node modules recursively:\n\n``` javascript\nvar promisify = require(\"promisify-node\");\nvar fs = promisify(\"fs\");\n\n// This function has been identified as an asynchronous function so it has\n// been automatically wrapped.\nfs.readFile(\"/etc/passwd\").then(function(contents) {\n  console.log(contents);\n});\n```\n\nWrap a single function:\n\n``` javascript\nvar promisify = require(\"promisify-node\");\n\nfunction async(callback) {\n  callback(null, true);\n}\n\n// Convert the function to return a Promise.\nvar wrap = promisify(async);\n\n// Invoke the newly wrapped function.\nwrap().then(function(value) {\n  console.log(value === true);\n});\n```\n\nWrap a method on an Object:\n\n``` javascript\nvar promisify = require(\"promisify-node\");\n\nvar myObj = {\n  myMethod: function(a, b, cb) {\n    cb(a, b);\n  }\n};\n\n// No need to return anything as the methods will be replaced on the object.\npromisify(myObj);\n\n// Intentionally cause a failure by passing an object and inspect the message.\nmyObj.myMethod({ msg: \"Failure!\" }, null).then(null, function(err) {\n  console.log(err.msg);\n});\n```\n\nWrap without mutating the original:\n```javascript\nvar promisify = require(\"promisify-node\");\n\nvar myObj = {\n  myMethod: function(a, b, cb) {\n    cb(a, b);\n  }\n};\n\n// Store the original method to check later\nvar originalMethod = myObj.myMethod;\n\n// Now store the result, since the 'true' value means it won't mutate 'myObj'.\nvar promisifiedObj = promisify(myObj, undefined, true);\n\n// Intentionally cause a failure by passing an object and inspect the message.\npromisifiedObj.myMethod({ msg: \"Failure!\" }, null).then(null, function(err) {\n  console.log(err.msg);\n});\n\n// The original method is still intact\nassert(myObj.myMethod === originalMethod);\nassert(promisifiedObj.myMethod !== myObj.myMethod);\n```\n\n### Tests ###\n\nRun the tests after installing dependencies with:\n\n``` bash\nnpm test\n```\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnodegit%2Fpromisify-node","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnodegit%2Fpromisify-node","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnodegit%2Fpromisify-node/lists"}