Node.js SDK
Install the Logdash Node.js SDK, send your first log and your first metric.
Install the package, paste your API key and the first log lands in the dashboard within a second. Everything below is copied from the Node.js SDK README.
Install
npm install @logdash/node Initialise
Create a project in Logdash, copy its API key and keep it in an environment variable. The key identifies the project the data lands in.
import { Logdash } from '@logdash/node';
const logdash = new Logdash(process.env.LOGDASH_API_KEY); Send a log
import { Logdash } from '@logdash/node';
const logdash = new Logdash(process.env.LOGDASH_API_KEY);
logdash.info('Application started successfully');
logdash.error('An unexpected error occurred');
logdash.warn('Low disk space warning'); Send a metric
Metrics are named numbers. Set one to an absolute value or mutate it by a delta, and Logdash charts the history.
import { Logdash } from '@logdash/node';
const logdash = new Logdash(process.env.LOGDASH_API_KEY);
// to set absolute value
logdash.setMetric('users', 0);
// to modify existing metric
logdash.mutateMetric('users', 1); Works with
- Express
- NestJS
- Fastify
- Next.js
- SvelteKit
- Bun
FAQ
Does it work with TypeScript?
Yes. Every example in the README is TypeScript and `Logdash` is a named export. The same package runs on Node, Bun and Deno.
How do I stop losing logs when the process exits?
Await `logdash.flush()` before you exit. It sends everything still queued, which matters in short-lived processes like cron jobs and serverless handlers.
Can I point it at a self-hosted instance?
Yes. Pass `options.host` to the constructor. It defaults to `https://api.logdash.io`.