
Security News
Feross on the 10 Minutes or Less Podcast: Nobody Reads the Code
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.
@logtail/node
Advanced tools
New to Logtail? Here's a low-down on logging in JavaScript.
@logtail/nodeThis NPM library is for logging in Node.js.
If you have a universal or client-side app that requires logging in the browser, check out @logtail/browser or @logtail/js (which combines the two packages.)
Here's how to get started:
Install the package directly from NPM:
npm i @logtail/node
In ES6/Typescript, import the Logtail class:
import { Logtail } from "@logtail/node";
For CommonJS, require the package:
const { Logtail } = require("@logtail/node");
Simply pass your Logtail.com source access token as a parameter to a new Logtail instance (you can grab it from Logtail.com):
const logtail = new Logtail("logtail-access-token");
This Node.js library extends @logtail/core, which provides a simple API for logging, adding middleware and more.
Visit the relevant readme section for more info/how-to:
In addition to .log|debug|info|warn|error() returning a Promise, the Node.js logger offers a .pipe() function for piping successfully synchronized logs to any writable stream.
This makes it trivial to additionally save logs to a file, stream logs over the network, or interface with other loggers that accept streamed data.
Here's a simple example of saving logs to a logs.txt file:
// Import the Node.js `fs` lib
import * as fs from "fs";
// Import the Node.js Logtail library
import { Logtail } from "@logtail/node";
// Open a writable stream to `logs.txt`
const logsTxt = fs.createWriteStream("./logs.txt");
// Create a new Logtail instance, and pipe output to `logs.txt`
const logtail = new Logtail("logtail-access-token");
logtail.pipe(logsTxt);
// When you next log, `logs.txt` will get a JSON string copy
logtail.log("This will also show up in logs.txt");
Streamed logs passed to your write stream's .write() function will be JSON strings in the format of type ILogtailLog, and always contain exactly one complete log after it has been transformed by middleware and synced with Logtail.com.
e.g:
{"dt":"2018-12-29T08:38:33.272Z","level":"info","message":"message 1"}
If you want to further process logs in your stream, remember to JSON.parse(chunk.toString()) the written 'chunk', to turn it back into an ILogtailLog object.
Calls to .pipe() will return the passed writable stream, allowing you to chain multiple .pipe() operations or access any other stream function:
// Import a 'pass-through' stream, to prove it works
import { PassThrough } from "stream";
// This stream won't do anything, except copy input -> output
const passThroughStream = new PassThrough();
// Passing to multiple streams works...
logtail.pipe(passThroughStream).pipe(logsTxt);
FAQs
Better Stack Node.js logger (formerly Logtail)
The npm package @logtail/node receives a total of 152,883 weekly downloads. As such, @logtail/node popularity was classified as popular.
We found that @logtail/node demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.

Research
/Security News
Campaign of 108 extensions harvests identities, steals sessions, and adds backdoors to browsers, all tied to the same C2 infrastructure.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.