Metrics

ReadMe Documentation

Welcome to the ReadMe Documentation, where you'll find comprehensive guides and community support to help you start working with ReadMe as quickly as possible!

Get Started

Sending Logs to ReadMe with Node.js

Any issues?

Integrations can be tricky! Contact support if you have any questions/issues.

It's super easy to send your API logs to ReadMe and get deep insights into your API's usage.

To begin, install the readmeio package from npm.

npm install readmeio --save

Once you have the package installed, you just need to add the middleware to express, and that's it!

const readme = require('readmeio');

app.use(readme.metrics('', req => ({
  id: req.project._id,
  label: req.project.subdomain,
  email: req.project.owner
})));

There are three things you can pass to readme.metrics, the ReadMe API Key, a function that takes the req object and returns an object describing the user (in the case above, it just returns their apiKey to identify the caller), and an options function that I will talk about later.

Identifying the API Caller

There are three fields that you can use to identify the user making the API call. We recommend passing all three to get the most insights about your API.

const readme = require('readmeio');

app.use(readme.metrics('', req => ({
  id: req.project._id,
  label: req.project.subdomain,
  email: req.project.owner
})));
Field
Usage

id

Required Unique identifier for the caller. This can be anything that is unique such as an id of this user in your database

label

This will be used to identify the user on ReadMe, since it's much easier to remember a name than a unique identifier

email

Email of the person that is making the call

Configuration Options

There are a few options you can pass in to change how the logs are sent to ReadMe. These are passed in an object as the third parameter to the readme.metrics

const readme = require('readmeio');
const env = process.env.NODE_ENV;

app.use(readme.metrics('', req => ({
  id: req.project.apiKey,
  label: req.project.subdomain,
}), {
  development: env !== 'production',
  bufferLength: 1,
}));
Option
Use

development

default: false If true, the log will be separate from normal production logs. This is great for separating staging or test data from data coming from customers

bufferLength

default: 10 By default, we only send logs to ReadMe after 10 requests are made. Depending on the usage of your API it make make sense to send logs more or less frequently

Updated 6 days ago


Sending Logs to ReadMe with Node.js


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.