Skip to content
On this page

Workers

Workers are are the new standard for writing HTTP servers in JS/TS. Each Worker is deployed to its own unique URL and ran globally at the network edge. Workers are a convenient yet powerful way to automate API interactions directly from your browser. Powered by the Netzo SDK, workers allow anything from simple workflows to complex automations.

Workers overview

Workers in Netzo are developed using Deno, a simple, modern and secure runtime for JavaScript and TypeScript. Netzo deploys Workers around the world instantly on the click of a button, and runs them closest to users at the network edge.

Using Workers provides the following benefits:

  • Builds on the Web: use fetch, WebSocket, or URL just like in the browser
  • Built-in support for TypeScript and JSX: type safe code, and intuitive server side rendering without a build step
  • Web compatible ES modules: import dependencies just like in a browser, without the need for explicit installation
  • Extremely fast: deploy in less than a second, serve globally close to users
  • Deploy from URL: deploy code with nothing more than a URL

Types of Files in Workers

The following table gives an overview of the currently supported types of Workers:

TypeContent TypeStatus
TS Workersapplication/typescript
JS Workersapplication/javascript
TSX Workersapplication/tsx
JSX Workersapplication/jsx

Key: ✅ - supported, ⌛ - work in progress, ❔ - in consideration, N/A - not applicable

The file extension of the Worker file will determine its content type. These file types will be executed as-is, without the need for a build step. The following file extensions are supported:

.js is JavaScript

Plain and simple vanilla JavaScript with all modern features.

const Foo = () => {
    return React.createElement("div", null, "Hello World!");
};

.ts is TypeScript

Microsoft's way of adding "concrete" types to JavaScript

const Foo: FunctionalComponent = () => {
    return React.createElement("div", null, "Hello World!");
};

.jsx is JavaScript but with JSX enabled

JSX is React's language extension to allow you to write markup directly in code which is then compiled to plain JavaScript with the JSX replaced with direct API calls to React.createElement or whatever API is targeted

const Foo = () => {
    return <div>Hello World!</div>;
};

.tsx is JSX but with TypeScript enabled

Its similar to jsx except it's TypeScript with the JSX language extension

const Foo: FunctionalComponent = () => {
  return <div>Hello World!</div>
}

Runtime APIs

The following Web and Deno APIs are supported on the runtime.

  • addEventListener
  • Cache
  • Durable Objects
  • Encoding
  • Fetch
  • FetchEvent
  • Headers
  • HTMLRewriter
  • KV
  • Request
  • Response
  • ScheduledEvent
  • Streams
  • Web Crypto
  • Web standards
  • WebSockets
  • eval()
  • new Function()

INFO

To learn more, you can always head over to the Deno documentation

Creating Workers

  1. Head over to the Workers page within a Workspace and click the Create button.

  2. Give a unique name for the worker and select a starting template. We'll select the basic TypeScript example for now.

  3. Add the necessary environment variables in the drawer to the right.

Invoking Workers

Workers are invoked via HTTP requests invoke a Worker, These can be made either manually (default), on a schedule (soon) or in response to a real-time event (soon).

Deployment

Note that deploying a Worker will save its latest changes but won't actually boot the new deployment until invoking it for the first time. Due to this, the first invocation after deployment could take a bit longer, following invocations should be almost instant.

Workers has loaded