Skip to content

Pantheon-Labs/Jiter-Node

Repository files navigation

License Build Code Quality Tests CodeQL codecov npm version

@jiter/node

The official Node SDK for Jiter

Getting Started

1️⃣ Install the Package

npm i @jiter/node

# or

yarn add @jiter/node

2️⃣ Initialize Jiter

import Jiter, { JiterConfig } from '@jiter/node';

const config: JiterConfig = { apiKey: 'YOUR_API_KEY' };
Jiter.init(config);

🔐 Do not to include your API key in code; use a package like dotenv to securely load your token via process.env

JavaScript example
const Jiter = require('@jiter/node');

Jiter.init({ apiKey: 'YOUR_API_KEY' });

3️⃣ Make Your First Event

const fifteenMinutesFromNow = new Date(Date.now() + 1000 * 60 * 15);

try {
  const createdEvent = await Jiter.Events.createEvent({
    destination: `${YOUR_API_URL}/webhooks/jiter`,
    payload: 'Hello there!',
    scheduledTime: fifteenMinutesFromNow.toISOString(),
  });

  console.log(createdEvent);
} catch (error) {
  if (isJiterError(error)) {
    console.log(`${error.code} - ${error.response?.data}`);
  } else {
    console.error(error);
  }
}