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.
- TypeScript
- JavaScript
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.
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:
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();
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 addlogLevel: "quiet"
to theInterval
constructor to silence informational logs and warnings if desired.
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:
const path = require("path");
const { Interval } = require("@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();
const { Action, io } = require("@interval/sdk");
module.exports = 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 addlogLevel: "quiet"
to theInterval
constructor to silence informational logs and warnings if desired.