1.4.3 • Published 4 years ago

node-cloudworker v1.4.3

Weekly downloads
13
License
MIT
Repository
github
Last release
4 years ago

The node-cloudworker is a cloudflare worker shim for node combined with a small webserver, enabling debugging locally. It should not be used in production.

It's most likely not as close to the production environment as https://github.com/dollarshaveclub/cloudworker, which most of the runtime has been borrowed from, but it makes debugging and testing possible.

Installing

Installing via NPM:

npm install node-cloudworker --save

Package Usage

const ncw = require('node-cloudworker');

// Some handlers may depend on the shims
ncw.applyShims();

const handler = event => {
    return new Response('hello', { status: 200 });
};

ncw.start(handler);

Cloudflare API's

Cloudflare exposes some cloudflare-specific API's inside the workers. Parts of these are supported with shims.

Cache

The cache api is borrowed from the Cloudworker repo.

KV-Storage (Beta)

The kv-storage api is using the Cloudflare rest-api to access the KV-Storage. It requires some configuration when applying the shims so that it can access the cloudflare api's:

ncw.applyShims({
  kv: {
    accountId: process.env.CLOUDFLARE_ACCOUNT_ID,
    authEmail: process.env.CLOUDFLARE_AUTH_EMAIL,
    authKey: process.env.CLOUDFLARE_AUTH_KEY,
    bindings: [
      {
        variable: 'TEST',
        namespace: process.env.KV_STORAGE_NAMESPACE,
      },
    ],
  },
});

It is also possible to use the local filesystem to mock KV-Storage. So far it only supports get requests:

ncw.applyShims({
  kv: {
    accountId: process.env.CLOUDFLARE_ACCOUNT_ID,
    authEmail: process.env.CLOUDFLARE_AUTH_EMAIL,
    authKey: process.env.CLOUDFLARE_AUTH_KEY,
    bindings: [
      {
        useFilesystem: true,
        variable: 'TEST_FS',
        namespace: 'examples/testfs',
      },
    ],
  },
});
1.4.3

4 years ago

1.4.2

4 years ago

1.4.1

4 years ago

1.4.0

4 years ago

1.3.4

4 years ago

1.3.3

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.0

4 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago