UNPKG

5.7 kBMarkdownView Raw
1[//]: # "This README.md file is auto-generated, all changes to this file will be lost."
2[//]: # "To regenerate it, use `python -m synthtool`."
3<img src="https://avatars2.githubusercontent.com/u/2810941?v=3&s=96" alt="Google Cloud Platform logo" title="Google Cloud Platform" align="right" height="96" width="96"/>
4
5# [Google Cloud Common Promisify: Node.js Client](https://github.com/googleapis/nodejs-promisify)
6
7[![release level](https://img.shields.io/badge/release%20level-stable-brightgreen.svg?style=flat)](https://cloud.google.com/terms/launch-stages)
8[![npm version](https://img.shields.io/npm/v/@google-cloud/promisify.svg)](https://www.npmjs.org/package/@google-cloud/promisify)
9
10
11
12
13A simple utility for promisifying functions and classes.
14
15
16A comprehensive list of changes in each version may be found in
17[the CHANGELOG](https://github.com/googleapis/nodejs-promisify/blob/main/CHANGELOG.md).
18
19* [Google Cloud Common Promisify Node.js Client API Reference][client-docs]
20
21* [github.com/googleapis/nodejs-promisify](https://github.com/googleapis/nodejs-promisify)
22
23Read more about the client libraries for Cloud APIs, including the older
24Google APIs Client Libraries, in [Client Libraries Explained][explained].
25
26[explained]: https://cloud.google.com/apis/docs/client-libraries-explained
27
28**Table of contents:**
29
30
31* [Quickstart](#quickstart)
32
33 * [Installing the client library](#installing-the-client-library)
34 * [Using the client library](#using-the-client-library)
35* [Samples](#samples)
36* [Versioning](#versioning)
37* [Contributing](#contributing)
38* [License](#license)
39
40## Quickstart
41
42### Installing the client library
43
44```bash
45npm install @google-cloud/promisify
46```
47
48
49### Using the client library
50
51```javascript
52const {promisify} = require('@google-cloud/promisify');
53
54/**
55 * This is a very basic example function that accepts a callback.
56 */
57function someCallbackFunction(name, callback) {
58 if (!name) {
59 callback(new Error('Name is required!'));
60 } else {
61 callback(null, `Well hello there, ${name}!`);
62 }
63}
64
65// let's promisify it!
66const somePromiseFunction = promisify(someCallbackFunction);
67
68async function quickstart() {
69 // now we can just `await` the function to use it like a promisified method
70 const [result] = await somePromiseFunction('nodestronaut');
71 console.log(result);
72}
73quickstart();
74
75```
76It's unlikely you will need to install this package directly, as it will be
77installed as a dependency when you install other `@google-cloud` packages.
78
79
80## Samples
81
82Samples are in the [`samples/`](https://github.com/googleapis/nodejs-promisify/tree/main/samples) directory. Each sample's `README.md` has instructions for running its sample.
83
84| Sample | Source Code | Try it |
85| --------------------------- | --------------------------------- | ------ |
86| Quickstart | [source code](https://github.com/googleapis/nodejs-promisify/blob/main/samples/quickstart.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-promisify&page=editor&open_in_editor=samples/quickstart.js,samples/README.md) |
87
88
89
90The [Google Cloud Common Promisify Node.js Client API Reference][client-docs] documentation
91also contains samples.
92
93## Supported Node.js Versions
94
95Our client libraries follow the [Node.js release schedule](https://nodejs.org/en/about/releases/).
96Libraries are compatible with all current _active_ and _maintenance_ versions of
97Node.js.
98If you are using an end-of-life version of Node.js, we recommend that you update
99as soon as possible to an actively supported LTS version.
100
101Google's client libraries support legacy versions of Node.js runtimes on a
102best-efforts basis with the following warnings:
103
104* Legacy versions are not tested in continuous integration.
105* Some security patches and features cannot be backported.
106* Dependencies cannot be kept up-to-date.
107
108Client libraries targeting some end-of-life versions of Node.js are available, and
109can be installed through npm [dist-tags](https://docs.npmjs.com/cli/dist-tag).
110The dist-tags follow the naming convention `legacy-(version)`.
111For example, `npm install @google-cloud/promisify@legacy-8` installs client libraries
112for versions compatible with Node.js 8.
113
114## Versioning
115
116This library follows [Semantic Versioning](http://semver.org/).
117
118
119
120This library is considered to be **stable**. The code surface will not change in backwards-incompatible ways
121unless absolutely necessary (e.g. because of critical security issues) or with
122an extensive deprecation period. Issues and requests against **stable** libraries
123are addressed with the highest priority.
124
125
126
127
128
129
130More Information: [Google Cloud Platform Launch Stages][launch_stages]
131
132[launch_stages]: https://cloud.google.com/terms/launch-stages
133
134## Contributing
135
136Contributions welcome! See the [Contributing Guide](https://github.com/googleapis/nodejs-promisify/blob/main/CONTRIBUTING.md).
137
138Please note that this `README.md`, the `samples/README.md`,
139and a variety of configuration files in this repository (including `.nycrc` and `tsconfig.json`)
140are generated from a central template. To edit one of these files, make an edit
141to its templates in
142[directory](https://github.com/googleapis/synthtool).
143
144## License
145
146Apache Version 2.0
147
148See [LICENSE](https://github.com/googleapis/nodejs-promisify/blob/main/LICENSE)
149
150[client-docs]: https://googleapis.dev/nodejs/promisify/latest
151
152[shell_img]: https://gstatic.com/cloudssh/images/open-btn.png
153[projects]: https://console.cloud.google.com/project
154[billing]: https://support.google.com/cloud/answer/6293499#enable-billing
155
156[auth]: https://cloud.google.com/docs/authentication/getting-started