Migrating from @logdash/js-sdk to @logdash/node
The new @logdash/node package provides a simpler, unified API that puts logging and metrics into a single interface. This guide will help you migrate your existing codebase.
What Changed
| Aspect | Old (@logdash/js-sdk) | New (@logdash/node) |
|---|---|---|
| Package | @logdash/js-sdk | @logdash/node |
| Import | import { createLogDash } from '@logdash/js-sdk' | import { Logdash } from '@logdash/node' |
| Initialization | const { logger, metrics } = createLogDash({ apiKey: '...' }) | const logdash = new Logdash('...') |
| Logging | logger.info() / logger.error() / logger.warn() | logdash.info() / logdash.error() / logdash.warn() |
| Set Metric | metrics.set('users', 0) | logdash.setMetric('users', 0) |
| Mutate Metric | metrics.mutate('users', 1) | logdash.mutateMetric('users', 1) |
New Features
Namespaced Logging
Create scoped loggers for different parts of your application.
const authLogdash = logdash.withNamespace('auth');
authLogdash.info('User logged in');Graceful Shutdown
Ensure all logs and metrics are sent before your application exits.
await logdash.flush();Migrate with AI
Copy the migration prompt below and paste it into your AI assistant (Claude, ChatGPT, Cursor, etc.) to automatically migrate your codebase.
AI Migration Prompt
Click to copy the prompt to your clipboard
Migrate my codebase from @logdash/js-sdk to @logdash/node. Apply these changes:
docs: @https://raw.githubusercontent.com/logdash-io/node-sdk/refs/heads/main/README.md
1. Replace package: Change `@logdash/js-sdk` to `@logdash/node`
2. Replace import: Change `import { createLogDash } from '@logdash/js-sdk'` to `import { Logdash } from '@logdash/node'`
3. Replace initialization: Change `const { logger, metrics } = createLogDash({ apiKey: '...' })` to `const logdash = new Logdash('...')`
4. Replace logger calls: Change `logger.info/error/warn/debug()` to `logdash.info/error/warn/debug()`
5. Replace metrics calls: Change `metrics.set()` to `logdash.setMetric()` and `metrics.mutate()` to `logdash.mutateMetric()`
6. On program exit, call `logdash.flush()` to ensure all logs and metrics are sent.
7. Utilize namespaces to organize logs by domain: Create scoped loggers using `const authLogdash = logdash.withNamespace('auth')` for different parts of your application (e.g., 'auth', 'payments', 'api'). Use these namespaced instances for logging within their respective modules.
namespaces should be plural, so e.g. log -> logs, metrics -> metrics, etc. but e.g. auth -> auth.
Keep the same API key values. The new SDK uses a class-based API where logging and metrics are methods on the same Logdash instance.