Installing Logtail JavaScript client


Logtail allows you to collect logs directly from both backend and frontend code, of your Node.js application. Supported language versions are:

  • Node.js 12 or newer

Installing Logtail Node.js client

Both backend and frontend

If your project contains both Node.js backend code and frontend code as well, you can use universal package @logtail/js which combines the node and browser packages:

First, install the Logtail library using the npm package manager:

npm install @logtail/js

Then import or require it in your code:

// in your backend code:
const { Node: Logtail } = require("@logtail/js");

// in your frontend code:
import { Browser as Logtail } from "@logtail/js";

Backend only

Install Logtail library for your Node.js backend code using the npm package manager.

npm install @logtail/node

Then you can either require it or import it into your codebase

// require logtail class
const { Logtail } = require("@logtail/node");

// or import if you're using ES modules:
import { Logtail } from "@logtail/node";

Frontend only

Install Logtail library for your frontend code using the npm package manager:

npm install @logtail/browser

Then import the Logtail class:

// import logtail class
import { Logtail } from "@logtail/browser";

Another option is to use Content Delivery Network. You can import Logtail using the CDN by adding the following line into a page header.

<script src="[email protected]/dist/umd/logtail.js"></script>

How it works in action

Here is an example of how to send logs from your Node.js application to Logtail.

For a more detailed example, please see the JavaScript + Node.js example project on GitHub  .

Example: Snippet added to your app
const { Logtail } = require("@logtail/node");

const logtail = new Logtail("<source-token>");"logtail integration is ready");
logtail.warn("log structured data", {
    item: {
        url: "",
        price: 100.00
Example: JSON rows sent to Logtail
    "dt": "2021-03-29T11:24:54.788Z",
    "level": "info",
    "message": "logtail integration is ready"

    "dt": "2021-03-29T11:24:54.788Z",
    "level": "warn",
    "message": "log structured data",
    "item": {
        "url": "",
        "price": 100.00