Back to Guides
Node.js Integration Guide (TypeScript)
Learn how to integrate Sift Dev logging with your Node.js applications using TypeScript.
1. Installation
Install the Sift Dev Logger SDK using npm:
npm i sift-dev-logger
2. Environment Setup
Create a .env
file in your project root.
Loading...
# Your Sift Dev endpoint and api key
SIFT_DEV_ENDPOINT=http://<YOUR-ORG-ID>.app.trysift.dev:8000
SIFT_DEV_INGEST_KEY=<YOUR-API-KEY>
# Optional configuration (defaults shown below)
SIFT_DEV_SERVICE_NAME=nodejs-app
SIFT_DEV_SERVICE_INSTANCE_ID=instance-1
NODE_ENV=development
BATCH_DELAY_MILLIS=5000
MAX_BATCH_SIZE=100
EXPORT_TIMEOUT_MILLIS=30000
3. Configuration (Optional)
💡 Configuration Interface
The SDK provides TypeScript types for all configuration options:
1interface SiftDevConfig {
2 sift_dev_endpoint?: string;
3 sift_dev_ingest_key?: string;
4 service_name?: string;
5 service_instance_id?: string;
6 env?: string;
7 batch_delay_millis?: number;
8 max_batch_size?: number;
9 export_timeout_millis?: number;
10 default_attributes?: LogAttributes;
11}
💡 Configuration Options
- Environment variables are automatically detected from your
process.env
object if present - Manual configuration via code is available for more control
- Configure early in your application startup if using manual configuration
- Full TypeScript support with type definitions included
If you want to configure the logger in your code instead of using environment variables:
1import { configureLogger } from 'sift-dev-logger';
2
3// Configuration with environment variables and overrides
4const config: Partial<SiftDevConfig> = {
5 sift_dev_endpoint: process.env.SIFT_DEV_ENDPOINT,
6 sift_dev_ingest_key: process.env.SIFT_DEV_INGEST_KEY,
7 service_name: process.env.SIFT_DEV_SERVICE_NAME,
8 service_instance_id: process.env.SIFT_DEV_SERVICE_INSTANCE_ID,
9 env: process.env.NODE_ENV,
10 batch_delay_millis: process.env.BATCH_DELAY_MILLIS ? parseInt(process.env.BATCH_DELAY_MILLIS, 10) : undefined,
11 max_batch_size: process.env.MAX_BATCH_SIZE ? parseInt(process.env.MAX_BATCH_SIZE, 10) : undefined,
12 export_timeout_millis: process.env.EXPORT_TIMEOUT_MILLIS ? parseInt(process.env.EXPORT_TIMEOUT_MILLIS, 10) : undefined,
13};
14
15configureLogger(config);
4. Usage
Start logging with structured data in your application:
1import { getLogger } from 'sift-dev-logger';
2
3// Get a logger instance
4const logger = getLogger({ component: 'user-service' });
5
6// Basic logging
7logger.info('Application started');
8
9// With additional attributes
10logger.info('User logged in', {
11 userId: '123',
12 action: 'login'
13});
14
15// Error handling
16try {
17 throw new Error('Database connection failed');
18} catch (error) {
19 logger.error('Connection error', error, {
20 database: 'users'
21 });
22}
5. Advanced Usage
Next Steps
Now that you've set up logging in your Node.js application:
- View your logs in the Logs Dashboard
- Set up alerts and notifications
- Configure custom log attributes for better filtering
- Explore our other framework integrations