FireTail Node JS library

Created:
July 15, 2024
Updated:
July 18, 2024

Prerequisites

  • Node.js v14 or later with Express v4+ or AWS Lambda.

Clone the repository

Clone the JavaScript quickstarts GitHub repository.


git clone https://github.com/FireTail-io/javascript-quickstarts.git

Install

In your command line, type:


$ npm install --save firetail-js

Express.js Example

Setup

Place your API YAML file (swagger.yaml) inside the root path of your application. Then run:


// ========== Let's import what we are going to need
const express = require('express');
const firetailSetup = require("@public.firetail.io/firetail-api");

// ========== Create our server
const app = express();

// ========== Setup request Body stash
app.use(
  express.raw({
    inflate: true, limit: '50mb', type: () => true,
  })
);

// ========== FireTail options
const firetailOpts = { dev: true, addApi: "./swagger.yaml" };

// ========== Install the FireTail middleware
app.use(firetailSetup(firetailOpts));

// ========== Add the endpoint you want
app.get('/', (req, res) => {
  res.send("FireTail sample");
});
//... They should match what's in your YAML

const port = 3001;
// ========== Start our server
app.listen(port, () => {
  console.log(`Example app listening on port ${port}`);
});

Running the Application

In your command line, type:


$ node index.js

AWS Lambda HelloWorld

Setup

  1. Place your API YAML file  inside the root path of your application. Then run:

// ========== Let's import what we are going to need
const firetailSetup = require("@public.firetail.io/firetail-api");

// ========== FireTail options
const firetailOpts = { addApi: "./swagger.yaml" };
// IF you run locally via 'serverless offline'
// firetailOpts.lambda = true; // Add the lambda flag

// ========== Install the FireTail middleware
const firetailWrapper = firetailSetup(firetailOpts);

// ========== Add the endpoint you want
module.exports.app = firetailWrapper((event, context) => {
  return {
    statusCode: 200,
    body: "FireTail sample"
  };
});
//... They should match what's in your YAML

Example Open API Spec


openapi: 3.0.1
info:
title: example spec
version: '0.1'
paths:
/greet:
    get:
    operationId: app.greeting
    responses:
        200:
        description: 200 response
        content: {}