
Node.js version 12 or higher is required.
Where do you want to collect your JavaScript logs from?
Collect logs from the backend code of your application.
Install Logtail Node NPM package:
npm install @logtail/node
Set up Logtail client:
const { Logtail } = require("@logtail/node");
const logtail = new Logtail("$SOURCE_TOKEN");
logtail.error("Something bad happend.");
logtail.info("Log message with structured data.", {
item: "Orange Soda",
price: 100.00
});
// Ensure that all logs are sent to Logtail
logtail.flush()
You should see your logs in Better Stack -> Live tail.
Node.js version 12 or higher is required.
Collect logs from your frontend code.
Install Logtail Browser NPM package:
npm install @logtail/browser
Set up Logtail client:
import { Logtail } from "@logtail/browser";
const logtail = new Logtail("$SOURCE_TOKEN");
Prefer using a Content Delivery Network?
Add Logtail import to your HTML page:
<script src="https://cdnjs.cloudflare.com/ajax/libs/logtail-browser/0.3.0/dist/umd/logtail.js" integrity="sha512-j7t6vlvFm1ANrX6dGt+NFtZqOjWeeNlPmAWCkf8mf1n7CMjZVubwUBEvNiVT0RE7voXE7ojiQBNWsAreLg00CA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
logtail.error("Something bad happend.");
logtail.info("Log message with structured data.", {
item: "Orange Soda",
price: 100.00
});
// Ensure that all logs are sent to Logtail
logtail.flush()
You should see your logs in Better Stack -> Live tail.
Collect logs from both backend and frontend code of your Node.js application.
Install Logtail JavaScript NPM package:
npm install @logtail/js
Set up Logtail client in backend and frontend code:
const { Node: Logtail } = require("@logtail/js");
const logtail = new Logtail("$SOURCE_TOKEN");
import { Browser as Logtail } from "@logtail/js";
const logtail = new Logtail("$SOURCE_TOKEN");
Log the same way in backend and frontend:
logtail.error("Something bad happend.");
logtail.info("Log message with structured data.", {
item: "Orange Soda",
price: 100.00
});
// Ensure that all logs are sent to Logtail
logtail.flush()
You should see your logs in Better Stack -> Live tail.
Node.js version 12 or higher is required.
Please let us know at hello@betterstack.com.
We're happy to help! π
Want to learning more about log levels and middleware in Node.js?
Continue to the Advanced usage of Logtail JavaScript client.
New to logging? See the Intro guide to Node.js logging and the Best practices for logging in Node.js.
Logging from browser? Some browsers (e.g. Brave, or some browser extensions) may block your logs from being sent. If you need to work around this issue, see possible workarounds on Github.
Using Bun runtime? No worries, our logging packages are tested in Bun as well as Node.
Package @logtail/js provides a convenient way to install and manage both @logtail/node and @logtail/browser NPM packages. You can install the packages separately if you wish to.