Skip to content

Commit 63edff9

Browse files
committed
Add promise support to pem API
1 parent 181a9c9 commit 63edff9

File tree

5 files changed

+260
-20
lines changed

5 files changed

+260
-20
lines changed

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ Here are some examples for creating an SSL key/cert on the fly, and running an H
2626
standard HTTPS port, but requires root permissions on most systems. To get around this, you could use a higher port
2727
number, like 4300, and use https://localhost:4300 to access your server.
2828

29+
> **Promise support:** Every asynchronous function in `pem` still accepts a Node-style callback and now returns a
30+
> `Promise` when no callback is provided. The legacy `pem.promisified` helper is deprecated; use the primary exports
31+
> directly for both callback and promise flows.
32+
2933
### Basic https
3034

3135
```javascript
@@ -62,9 +66,34 @@ pem.createCertificate({ days: 1, selfSigned: true }, function (err, keys) {
6266
})
6367
```
6468

69+
### Basic https with async/await
70+
71+
```javascript
72+
const https = require('https')
73+
const pem = require('pem')
74+
75+
async function main() {
76+
const keys = await pem.createCertificate({ days: 1, selfSigned: true })
77+
78+
const server = https.createServer({ key: keys.clientKey, cert: keys.certificate }, (req, res) => {
79+
res.end('o hai!')
80+
})
81+
82+
server.listen(443)
83+
}
84+
85+
main().catch((err) => {
86+
console.error(err)
87+
process.exit(1)
88+
})
89+
```
90+
6591
## API
6692
Please have a look into the [API documentation](https://dexus.github.io/pem/jsdoc/).
6793

94+
All asynchronous functions document below support both callback and promise styles. Invoke them without a callback to
95+
receive a `Promise` that resolves to the same value that would be passed to the callback.
96+
6897
_we had to clean up a bit_
6998
<!--
7099
### Create a dhparam key

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)