# @weglot/cloudworker

> node.js runner for Cloudflare Workers

Latest version **0.2.1** (published 2020-07-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install @weglot/cloudworker
pnpm add @weglot/cloudworker
yarn add @weglot/cloudworker
bun add @weglot/cloudworker
```

Provides the command `cloudworker`.

## Health

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

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

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.1 |
| Published | 2020-07-29 |
| First published | 2020-07-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 10 |
| Unpacked size | 446.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Maintainers | floran, nico2che |
| Keywords | cloudflare, service worker, workers, worker, cloudflare worker, cloudworker |

## Links

- npm: https://www.npmjs.com/package/@weglot/cloudworker
- Repository: https://github.com/weglot/cloudworker
- Homepage: https://github.com/weglot/cloudworker#readme
- Issues: https://github.com/weglot/cloudworker/issues
- npm.io page: https://npm.io/package/@weglot/cloudworker

## Dependencies (10)

- [atob](https://npm.io/package/atob.md) ^2.1.2
- [btoa](https://npm.io/package/btoa.md) ^1.2.1
- [moment](https://npm.io/package/moment.md) ^2.24.0
- [commander](https://npm.io/package/commander.md) ^6.0.0
- [lru-cache](https://npm.io/package/lru-cache.md) ^6.0.0
- [arraybuffer-equal](https://npm.io/package/arraybuffer-equal.md) ^1.0.4
- [node-webcrypto-ossl](https://npm.io/package/node-webcrypto-ossl.md) ^2.1.0
- [http-cache-semantics](https://npm.io/package/http-cache-semantics.md) ^4.0.3
- [web-streams-polyfill](https://npm.io/package/web-streams-polyfill.md) ^3.0.0
- [@dollarshaveclub/node-fetch](https://npm.io/package/@dollarshaveclub/node-fetch.md) ^3.2.0

## 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.2.1 (latest) — 2020-07-29
- 0.2.0 — 2020-07-29

## README

<img src="https://i.imgur.com/e0Asgu3.jpg">

---

This package is a fork from [dollarshaveclub/cloudworker](https://github.com/dollarshaveclub/cloudworker)

## Installing

Install via YARN:

```sh
yarn add --dev @weglot/cloudworker
```

## Package Usage

```
const Cloudworker = require("@weglot/cloudworker");

const simpleScript = `addEventListener('fetch', event => {
  event.respondWith(new Response('hello', {status: 200}))
})`;

const req = new Cloudworker.Request("https://myfancywebsite.com/someurl");
const cw = new Cloudworker(simpleScript);
cw.dispatch(req).then((res) => {
  console.log("Response Status: ", res.status);
  res.text().then((body) => {
    console.log("Response Body: ", body);
  });
});
```

## CLI Usage

```sh
Usage: cloudworker [options] <file>

Options:
  -p, --port <port>                   Port (default: 3000)
  -d, --debug                         Debug
  -s, --kv-set [variable.key=value]   Binds variable to a local implementation of Workers KV and sets key to value (default: [])
  -f, --kv-file [variable=path]       Set the filepath for value peristence for the local implementation of Workers KV (default: [])
  -w, --wasm [variable=path]          Binds variable to wasm located at path (default: [])
  -c, --enable-cache                  Enables cache <BETA>
  -r, --watch                         Watch the worker script and restart the worker when changes are detected
  --tls-key <tlsKey>                  Optional. Path to encryption key for serving requests with TLS enabled. Must specify --tls-cert when using this option.
  --tls-cert <tlsCert>                Optional. Path to certificate for serving requests with TLS enabled. Must specify --tls-key when using this option.
  --https-port <httpsPort>            Optional. Port to listen on for HTTPS requests. Must specify --tls-cert and --tls-key when using this option. May not be the same value as --port.
  -h, --help                          output usage information
```

### Simple

```sh
cloudworker example/example.js
curl localhost:3000/
```

```sh
cloudworker --debug example/example.js
curl localhost:3000/
```

### Workers KV

```sh
cloudworker --debug --kv-set KeyValueStore.key=value --kv-set KeyValueStore.hello=world example/example-kv.js
curl localhost:3000/
```

### Workers KV with Persistence

```sh
cloudworker --debug --kv-file KeyValueStore=kv.json --kv-set KeyValueStore.key=value --kv-set KeyValueStore.hello=world example/example-kv.js
curl localhost:3000/
```

### WebAssembly

#### Simple

```sh
cloudworker --debug --wasm Wasm=example/simple.wasm example/example-wasm-simple.js
curl localhost:3000/
```

[WebAssembly Source](https://github.com/mdn/webassembly-examples/blob/master/js-api-examples/simple.wat)

#### Inverse Square Root

```sh
cloudworker --debug --wasm isqrt=example/isqrt.wasm example/example-wasm-isqrt.js
curl localhost:3000/?num=9
```

[WebAssembly Source](https://developers.cloudflare.com/workers/api/resource-bindings/webassembly-modules/)

#### Resizer

```sh
cloudworker --debug --wasm RESIZER_WASM=example/resizer.wasm example/example-wasm-resizer.js
curl localhost:3000/wasm-demo/dogdrone.png?width=210 # or open in browser
```

[WebAssembly Source](https://github.com/cloudflare/cloudflare-workers-wasm-demo)

## Cloudflare Worker Compatibility

Cloudworker strives to be as similar to the Cloudflare Worker runtime as possible. A script should behave the same when executed by Cloudworker and when run within Cloudflare Workers. Please file an issue for scenarios in which Cloudworker behaves differently. As behavior differences are found, this package will be updated to match the Cloudflare Worker runtime. This may result in breakage if scripts depended on those behavior differences.

## Release Process

For beta releases:

- Create a new release branch named `v[version]-beta`. e.g. `v0.0.10-beta`
- Run `npm version [version]-beta.[beta number]`. e.g `npm version 0.0.10-beta.1`
- Push branch to origin.
- Run `npm publish --tag beta`.
- Create a new release in Github using tag created by `npm version`, write relevant release notes, and ensure "This is a pre-release" is checked.
- Bug fixes and changes should be made on feature branches, merged into master, and then merged into the release branch.
- Subsequent beta releases of the same beta version should be made off of the same release branch.

For production releases:

- Merge release branch (if one exists) into master.
- Run `npm version [version]`. e.g. `npm version 0.0.10`
- Push master to origin.
- Run `npm publish`.
- Create a new release in Github using tag created by `npm version` and copy release notes from beta.

## License

MIT

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