Harmono

Typescript SDK

Guide to using the Harmono Typescript

This guide will help you get started with integrating our SDK into your Typescript applications. We'll go over the installation process and how to use the SDK in your project.

Getting Started

To use the Harmono Typescript SDK, you first need to install it.

npm install harmono

This Typescript SDK can be used in different project/framework. We currently support Express, Fastify, and Koa.

Express

//Express
import express from "express";
import { HarmonoExpress } from "harmono"; //ESM
// OR
const { HarmonoExpress } = require("harmono"); //CommonJS
 
const app = express();
const monitor = HarmonoExpress({
  key: "<your-api-key>",
  host: "<your-host>",
  env: "production", // development | production.
});
 
app.use(monitor); // This middleware should be used before your routes.
 
/*
  Define your routes here.
*/
 
// Start Express server
app.listen(8080, () => {
  console.log(`App is running on port 8000`);
});

Fastify

//Fastify
import fastify from "fastify";
import { HarmonoFastify } from "harmono"; //ESM
// OR
const { HarmonoFastify } = require("harmono"); //CommonJS
 
const app = fastify();
const monitor = HarmonoFastify({
  key: "<your-api-key>",
  host: "<your-host>",
  env: "production", // development | production.
});
app.register(monitor);
 
// Start the server
const start = async () => {
  try {
    await fastify.listen({ port: 3000 });
    console.log("Server is running on http://localhost:3000");
  } catch (error) {
    console.error("Error starting server:", error);
    process.exit(1);
  }
};
 
start();

KOA

import Koa from "koa";
import { HarmonoKoa } from "harmono";
 
const app = new Koa();
const monitor = HarmonoKoa({
  key: "<your-api-key>",
  host: "<your-host>",
  env: "production", // development | production.
});
 
app.use(monitor); // Initialize the middleware.
 
/*
  Define your routes here.
*/
 
// Start your server
app.listen(3000);

Important Notes

  • Access Token: Replace YOUR_ACCESS_TOKEN with your actual access token. For security, consider using environment variables or a secrets management tool to store sensitive information.
  • Environment Configuration: You can set the env parameter to either production or development. On development, Harmono will not save any log to our DB - stritcly for development purposes only.
  • SDK Supports: I'm building this from the ground up from scratch and it's not so easy doing it myself. I plan to support other SDK (ofcourse!), but they might take a little bit of time :).

Conclusion

With this setup, you can start capturing events and integrating with the Harmono platform. If you're stuck, please let us know how we can help :).

Reach out to me if you're stuck!

On this page