Skip to content

Commit c81869d

Browse files
committed
docs(README): use ESM for examples
1 parent 3d86072 commit c81869d

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ Note that while setting a secret is optional on GitHub, it is required to be set
4343

4444
```js
4545
// install with: npm install @octokit/webhooks
46-
const { Webhooks, createNodeMiddleware } = require("@octokit/webhooks");
46+
import { Webhooks, createNodeMiddleware } from "@octokit/webhooks";
47+
import { createServer } from "node:http";
4748
const webhooks = new Webhooks({
4849
secret: "mysecret",
4950
});
@@ -52,7 +53,7 @@ webhooks.onAny(({ id, name, payload }) => {
5253
console.log(name, "event received");
5354
});
5455

55-
require("http").createServer(createNodeMiddleware(webhooks)).listen(3000);
56+
createServer(createNodeMiddleware(webhooks)).listen(3000);
5657
// can now receive webhook events at /api/github/webhooks
5758
```
5859

@@ -81,7 +82,7 @@ source.onmessage = (event) => {
8182
};
8283
```
8384

84-
`EventSource` is a native browser API and can be polyfilled for browsers that don’t support it. In node, you can use the [`eventsource`](https://github.com/EventSource/eventsource) package: install with `npm install eventsource`, then `const EventSource = require('eventsource')`
85+
`EventSource` is a native browser API and can be polyfilled for browsers that don’t support it. In node, you can use the [`eventsource`](https://github.com/EventSource/eventsource) package: install with `npm install eventsource`, then `import EventSource from "eventsource";)`
8586

8687
## API
8788

@@ -278,7 +279,7 @@ Additionally, if verification fails, rejects the returned promise and emits an `
278279
Example
279280

280281
```js
281-
const { Webhooks } = require("@octokit/webhooks");
282+
import { Webhooks } from "@octokit/webhooks";
282283
const webhooks = new Webhooks({
283284
secret: "mysecret",
284285
});
@@ -509,8 +510,8 @@ The `.removeListener()` method belongs to the `event-handler` module which can b
509510
### createNodeMiddleware()
510511

511512
```js
512-
const { createServer } = require("http");
513-
const { Webhooks, createNodeMiddleware } = require("@octokit/webhooks");
513+
import { createServer } from "node:http";
514+
import { Webhooks, createNodeMiddleware } from "@octokit/webhooks";
514515

515516
const webhooks = new Webhooks({
516517
secret: "mysecret",

0 commit comments

Comments
 (0)