Skip to main content
Big news! Interval has been acquired by Meter. Learn more →

Interval SDK

info

Before you can begin building tools with Interval, you must first deploy an instance of Interval Server. Follow the instructions in the Interval Server documentation to get started.

The Interval SDK is a pure JS Node.js module requiring Node.js version 16 or greater.

We built Interval from the ground up specifically for TypeScript and we strongly recommend using it when building your apps. Interval's I/O methods do the heavy lifting of parsing, sanitizing, and type checking all user input.

Adding Interval to an existing app

If you have one, we recommend adding Interval to your existing Node.js app. We've found that teams are able to move incredibly quickly by sharing code between their main app and internal tools built with Interval.

When your Interval actions are defined alongside the code in your main app, code sharing is as simple as importing shared functions and calling them within your actions.

To add Interval to your app:

npm install @interval/sdk

Once the SDK is installed, you can create a minimal Interval app:

src/interval.ts
import path from "path";
import { Interval } from "@interval/sdk";

const interval = new Interval({
endpoint: "wss://<YOUR INTERVAL SERVER URL>/websocket", // Don't forget the /websocket path!
apiKey: "<YOUR API KEY>", // get an API key from the Keys page in your Interval dashboard
routesDirectory: path.resolve(__dirname, "routes"),
});

// This is important! If you don't call listen(), your app won't connect to Interval.
interval.listen();
src/routes/hello_world.ts
import { Action, io } from "@interval/sdk";

export default new Action(async () => {
const name = await io.input.text("Your name");
return `Hello, ${name}`;
});

A few things to note:

  • Calling .listen() sets up a persistent connection between your app and Interval.
  • Actions are defined as a map of slug identifiers to async handler functions.
  • The Interval API key that you use determines whether your app will run in Dev mode or Live mode.
  • Starting with version 0.36.0 of the SDK, you can add logLevel: "quiet" to the Interval constructor to silence informational logs and warnings if desired.
Did this section clearly explain what you wanted to learn?