# h3-worker

> Use h3 in a (Cloudflare) worker

Latest version **0.0.18** (published 2021-10-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install h3-worker
pnpm add h3-worker
yarn add h3-worker
bun add h3-worker
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.18 |
| Published | 2021-10-30 |
| First published | 2021-10-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 14.1 KB |
| Known vulnerabilities | 0 (+5 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Jamie Curnow |
| Maintainers | jamiecurnow |
| Keywords | cloudflare, worker, h3, api |

## Links

- npm: https://www.npmjs.com/package/h3-worker
- Repository: https://github.com/JamieCurnow/h3-worker
- npm.io page: https://npm.io/package/h3-worker

## Dependencies (2)

- [h3](https://npm.io/package/h3.md) ^0.3.3
- [unenv](https://npm.io/package/unenv.md) ^0.3.10

## Alternatives

- [cron](https://npm.io/package/cron.md) — 4.9M weekly downloads
- [@vercel/queue](https://npm.io/package/@vercel/queue.md) — 731.6K weekly downloads
- [create-sonicjs](https://npm.io/package/create-sonicjs.md) — 1.6K weekly downloads
- [@exellix/jobs-api](https://npm.io/package/@exellix/jobs-api.md) — 941 weekly downloads
- [@forwardimpact/libskill](https://npm.io/package/@forwardimpact/libskill.md) — 575 weekly downloads

## Recent versions

- 0.0.18 (latest) — 2021-10-30
- 0.0.17 — 2021-10-30
- 0.0.16 — 2021-10-30
- 0.0.15 — 2021-10-30
- 0.0.14 — 2021-10-30
- 0.0.13 — 2021-10-30
- 0.0.12 — 2021-10-30
- 0.0.11 — 2021-10-30
- 0.0.10 — 2021-10-30
- 0.0.9 — 2021-10-30
- 0.0.8 — 2021-10-30
- 0.0.7 — 2021-10-14
- 0.0.6 — 2021-10-14
- 0.0.5 — 2021-10-14
- 0.0.4 — 2021-10-14
- … 2 more at https://npm.io/package/h3-worker/versions

## README

# h3-worker
Use [h3](https://github.com/unjs/h3) in a ([Cloudflare](https://developers.cloudflare.com/workers/)) worker!

This little package uses some helpers from [h3](https://github.com/unjs/h3) and [unenv](https://github.com/unjs/unenv) to make h3 apps work in a Cloudflare worker environment.

## Install

```bash
# Using npm
npm install h3-worker

# Using yarn
yarn add h3-worker
```

## Usage

- Set up your Cloudflare worker project - I recommend [worker-typescript-template](https://github.com/cloudflare/worker-typescript-template)
- Check out the [h3](https://github.com/unjs/h3) docs
- Write some routes and use the `handleEvent` method from `h3-worker` to `respondWith`

```ts
import { createApp, handleEvent } from 'h3-worker'

// Create the app
const app = createApp()

// Add some routes (no need to worry about order)
app.use('/', () => 'Hello world')
app.use('/json', () => ({ hello: 'JSON' }))

// Type the body if you like
app.use<{ firstName: string }>('/first-name', (req) => {
  const { body } = req
  return `Hi ${body.firstName}`
})

// Add the event listener
addEventListener('fetch', (event) => {
  // Respond with a handleEvent() call, passing in the event and your app. Options are optional
  event.respondWith(handleEvent(event, app, { basePath: '', sortStack: true }))
})
```

## TaDa!

---
_Source: https://npm.io/package/h3-worker · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
