Skip to content

Commit d98ac46

Browse files
dahliaclaude
andcommitted
Add Node.js support to documentation
Update documentation and build configuration to reflect Node.js support alongside Deno. Switch docs build from Bun to pnpm for consistency. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 5ff4003 commit d98ac46

File tree

10 files changed

+2519
-636
lines changed

10 files changed

+2519
-636
lines changed

.github/workflows/main.yaml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,15 @@ jobs:
127127
url: ${{ steps.deploy.outputs.page_url }}
128128
steps:
129129
- uses: actions/checkout@v4
130-
- uses: oven-sh/setup-bun@v2
130+
- uses: actions/setup-node@v4
131+
with:
132+
node-version: latest
133+
- uses: pnpm/action-setup@v4
131134
with:
132-
bun-version: latest
133-
- run: bun install
135+
version: 10
136+
- run: pnpm install
134137
working-directory: docs
135-
- run: bun run build
138+
- run: pnpm build
136139
env:
137140
PLAUSIBLE_DOMAIN: ${{ vars.PLAUSIBLE_DOMAIN }}
138141
SITEMAP_HOSTNAME: https://${{ vars.PLAUSIBLE_DOMAIN }}

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
"pico",
6868
"Pixelfed",
6969
"smallweb",
70+
"srvx",
7071
"Tailscale",
7172
"tsdown",
7273
"unfollow",

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,11 @@
44
==================
55

66
[![JSR][JSR badge]][JSR]
7+
[![npm][npm badge]][npm]
78
[![GitHub Actions][GitHub Actions badge]][GitHub Actions]
89
[![Codecov][Codecov badge]][Codecov]
910
[![Fediverse][Fediverse badge]][Fediverse]
1011

11-
> [!NOTE]
12-
> BotKit is still in early development. The API may change in the future.
13-
> Although it currently supports only Deno, it will support Node.js and Bun
14-
> later.
15-
1612
[BotKit] is a framework for creating [ActivityPub] bots. It is powered by
1713
[Fedify], a lower-level library for creating ActivityPub server applications.
1814
Unlike Mastodon bots, BotKit is designed to create a standalone ActivityPub bot,
@@ -63,6 +59,8 @@ For more information, see the [BotKit docs][BotKit].
6359
[BotKit]: https://botkit.fedify.dev/
6460
[JSR]: https://jsr.io/@fedify/botkit
6561
[JSR badge]: https://jsr.io/badges/@fedify/botkit
62+
[npm]: https://www.npmjs.com/package/@fedify/botkit
63+
[npm badge]: https://img.shields.io/npm/v/@fedify/botkit?logo=npm
6664
[GitHub Actions]: https://github.com/fedify-dev/botkit/actions/workflows/main.yaml
6765
[GitHub Actions badge]: https://github.com/fedify-dev/botkit/actions/workflows/main.yaml/badge.svg
6866
[Codecov]: https://codecov.io/gh/fedify-dev/botkit

docs/.vitepress/config.mts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ export default defineConfig({
8484
link: "https://jsr.io/@fedify/botkit",
8585
ariaLabel: "JSR",
8686
},
87+
{
88+
icon: "npm",
89+
link: "https://www.npmjs.com/package/@fedify/botkit",
90+
ariaLabel: "npm",
91+
},
8792
{
8893
icon: "discord",
8994
link: "https://discord.gg/bhtwpzURwd",

docs/bun.lock

Lines changed: 0 additions & 570 deletions
This file was deleted.

docs/concepts/bot.md

Lines changed: 64 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,14 @@ Running the bot
320320

321321
After you have instantiated a `Bot` object, you need to connect it to
322322
the HTTP server to run it. The `Bot` object comply with the [`fetch()`] API,
323-
so you can use it as a request handler for the [`deno serve`] command.
323+
so you can use it as a request handler for the [`deno serve`] command on Deno
324+
or [srvx] on Node.js.
325+
326+
[`fetch()`]: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API
327+
[`deno serve`]: https://docs.deno.com/runtime/reference/cli/serve/
328+
[srvx]: https://srvx.h3.dev/
329+
330+
### Deno
324331

325332
For example, if you have a `Bot` object named `bot`, and `export` it as
326333
a default export:
@@ -356,8 +363,53 @@ And your bot will be available at <http://localhost:8000/>.
356363
> deno serve -A --port=3000 ./bot.ts
357364
> ~~~~
358365
359-
[`fetch()`]: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API
360-
[`deno serve`]: https://docs.deno.com/runtime/reference/cli/serve/
366+
### Node.js
367+
368+
In Node.js, you should use the [srvx] package to run the bot. First, you need
369+
to install the *srvx* package:
370+
371+
::: code-group
372+
373+
~~~~ bash [npm]
374+
npm add srvx
375+
~~~~
376+
377+
~~~~ bash [pnpm]
378+
pnpm add srvx
379+
~~~~
380+
381+
~~~~ bash [Yarn]
382+
yarn add srvx
383+
~~~~
384+
385+
:::
386+
387+
Then, import [`serve()`] function from `srvx` module:
388+
389+
~~~~ typescript [bot.ts]
390+
import { serve } from "srvx";
391+
~~~~
392+
393+
Finally, you can run the bot using the [`serve()`] function at the end of
394+
the *bot.ts* file:
395+
396+
~~~~ typescript [bot.ts]
397+
const server = serve({
398+
...bot,
399+
port: 8000,
400+
});
401+
await server.ready();
402+
console.log(`Bot is running at ${server.url}`);
403+
~~~~
404+
405+
Then, you can run the bot using the following command:
406+
407+
~~~~ bash
408+
node --experimental-transform-types ./bot.ts
409+
~~~~
410+
411+
The above command will start the bot and it will be available at
412+
<http://localhost:8000/>:
361413

362414
### Exposing the bot to the public internet
363415

@@ -384,17 +436,23 @@ const bot = createBot<void>({
384436
// Omitted other options for brevity
385437
behindProxy: BEHIND_PROXY,
386438
});
387-
388-
export default bot;
389439
~~~~
390440

391441
Then, you can use the following command to run the bot with the `BEHIND_PROXY`
392442
environment variable set to `true`:
393443

394-
~~~~ bash
444+
::: code-group
445+
446+
~~~~ bash [Deno]
395447
BEHIND_PROXY=true deno serve -A --port 8000 ./bot.ts
396448
~~~~
397449

450+
~~~~ bash [Node.js]
451+
node --experimental-transform-types ./bot.ts
452+
~~~~
453+
454+
:::
455+
398456
Then, you can use the tunneling service to expose your bot to the public
399457
internet, for example, with [`fedify tunnel`]:[^1]
400458

docs/intro.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,7 @@ BotKit currently supports deployment through:
119119

120120
- [Deno Deploy] for serverless hosting
121121
- Docker containers on platforms like Fly.io and Railway
122-
- Self-hosted Deno runtime on your own server
123-
124-
> [!NOTE]
125-
> While Node.js and Bun support are planned for future releases,
126-
> the current version requires Deno.
122+
- Self-hosted Node.js or Deno runtime on your own server
127123

128124
[Deno Deploy]: https://deno.com/deploy
129125

docs/start.md

Lines changed: 91 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,48 +6,19 @@ description: >-
66
Getting started
77
===============
88

9-
Installing Deno
10-
---------------
11-
12-
> [!NOTE]
13-
> BotKit currently supports only [Deno]. Once BotKit is more stable, we will
14-
> support [Node.js] and [Bun].
15-
16-
BotKit is a TypeScript framework written in Deno. To install BotKit, you need
17-
to have Deno 2 or higher installed on your machine. There are [multiple ways to
18-
install Deno][1], but the easiest way is to use the following command:
19-
20-
::: code-group
21-
22-
~~~~ bash [Linux]
23-
curl -fsSL https://deno.land/install.sh | sh
24-
~~~~
25-
26-
~~~~ zsh [macOS]
27-
curl -fsSL https://deno.land/install.sh | sh
28-
~~~~
29-
30-
~~~~ powershell [Windows]
31-
irm https://deno.land/install.ps1 | iex
32-
~~~~
33-
34-
:::
35-
36-
[Deno]: https://deno.com/
37-
[Node.js]: https://nodejs.org/
38-
[Bun]: https://bun.sh/
39-
[1]: https://docs.deno.com/runtime/getting_started/installation/
40-
419

4210
Installing BotKit
4311
-----------------
4412

45-
Once you have Deno installed, you need to create a new project for your bot and
46-
install BotKit as a dependency:
13+
BotKit is available for both Node.js and Deno. You can install BotKit
14+
depending on your environment.
15+
16+
### Deno
17+
18+
You need to create a new project for your bot and install BotKit as
19+
a dependency:
4720

4821
~~~~ bash
49-
mkdir my-bot/
50-
cd my-bot/
5122
deno add jsr:@fedify/botkit
5223
~~~~
5324

@@ -57,14 +28,34 @@ to turn it on in your *deno.json* settings:
5728
~~~~ json [deno.json] {5}
5829
{
5930
"imports": {
60-
"@fedify/botkit": "jsr:@fedify/botkit@0.2.0"
31+
"@fedify/botkit": "jsr:@fedify/botkit@0.3.0"
6132
},
6233
"unstable": ["temporal"]
6334
}
6435
~~~~
6536

6637
[Temporal]: https://tc39.es/proposal-temporal/docs/
6738

39+
### Node.js
40+
41+
You can install BotKit from npm:
42+
43+
::: code-group
44+
45+
~~~~ bash [npm]
46+
npm add @fedify/botkit
47+
~~~~
48+
49+
~~~~ bash [pnpm]
50+
pnpm add @fedify/botkit
51+
~~~~
52+
53+
~~~~ bash [Yarn]
54+
yarn add @fedify/botkit
55+
~~~~
56+
57+
:::
58+
6859

6960
Creating a bot
7061
--------------
@@ -148,9 +139,14 @@ bot.onFollow = async (session, follower) => {
148139
Running the bot
149140
---------------
150141

151-
To run the bot, you need to first connect the bot to the HTTP server. We will
152-
utilize [`deno serve`] command. In order to connect the bot to Deno's HTTP
153-
server, you need to `export` the `bot` instance as a default export in
142+
To run the bot, you need to first connect the bot to the HTTP server. There
143+
are different ways to run the bot depending on the environment you are
144+
using. Here, we will show you how to run the bot in Deno and Node.js.
145+
146+
### Deno
147+
148+
We will utilize [`deno serve`] command. In order to connect the bot to Deno's
149+
HTTP server, you need to `export` the `bot` instance as a default export in
154150
the *bot.ts* file:
155151

156152
~~~~ typescript [bot.ts]
@@ -173,6 +169,61 @@ And your bot will be available at <http://localhost:8000/>.
173169

174170
[`deno serve`]: https://docs.deno.com/runtime/reference/cli/serve/
175171

172+
### Node.js
173+
174+
In Node.js, we will use the [srvx] package to run the bot. First, you need to
175+
install the *srvx* package:
176+
177+
::: code-group
178+
179+
~~~~ bash [npm]
180+
npm add srvx
181+
~~~~
182+
183+
~~~~ bash [pnpm]
184+
pnpm add srvx
185+
~~~~
186+
187+
~~~~ bash [Yarn]
188+
yarn add srvx
189+
~~~~
190+
191+
:::
192+
193+
Then, import [`serve()`] function from `srvx` module:
194+
195+
~~~~ typescript [bot.ts]
196+
import { serve } from "srvx";
197+
~~~~
198+
199+
Finally, you can run the bot using the [`serve()`] function at the end of
200+
the *bot.ts* file:
201+
202+
~~~~ typescript [bot.ts]
203+
const server = serve({
204+
...bot,
205+
port: 8000,
206+
});
207+
await server.ready();
208+
console.log(`Bot is running at ${server.url}`);
209+
~~~~
210+
211+
Then, you can run the bot using the following command:
212+
213+
~~~~ bash
214+
node --experimental-transform-types ./bot.ts
215+
~~~~
216+
217+
The above command will start the bot and it will be available at
218+
<http://localhost:8000/>:
219+
220+
~~~~
221+
Bot is running at http://localhost:8000/
222+
~~~~
223+
224+
[srvx]: https://srvx.h3.dev/
225+
[`serve()`]: https://srvx.h3.dev/guide/server
226+
176227

177228
Exposing the bot to the public internet
178229
---------------------------------------

0 commit comments

Comments
 (0)