Back to Guides
Node.js Integration Guide (JavaScript)
Learn how to integrate Sift Dev logging with your Node.js applications using JavaScript.
1. Installation
Install the Sift Dev Logger SDK using npm:
npm install 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 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
- Both CommonJS (
require
) and ES Modules (import
) are supported
If you want to configure the logger in your code instead of using environment variables:
1import { configureLogger } from 'sift-dev-logger';
2// Or using CommonJS:
3// const { configureLogger } = require('sift-dev-logger');
4
5configureLogger({
6 sift_dev_endpoint: process.env.SIFT_DEV_ENDPOINT,
7 sift_dev_ingest_key: process.env.SIFT_DEV_INGEST_KEY,
8 service_name: "configured-service",
9 service_instance_id: "instance-1",
10 env: "custom-env",
11 batch_delay_millis: 5000,
12 max_batch_size: 100,
13 export_timeout_millis: 30000,
14 default_attributes: {
15 deployment: "blue",
16 region: "us-west-2"
17 }
18});
4. Usage
Start logging with structured data in your application:
1import { getLogger } from 'sift-dev-logger';
2// Or using CommonJS:
3// const { getLogger } = require('sift-dev-logger');
4
5// Get a logger instance
6const logger = getLogger({ component: 'user-service' });
7
8// Basic logging
9logger.info('Application started');
10
11// With additional attributes
12logger.info('User logged in', {
13 userId: '123',
14 action: 'login'
15});
16
17// Error handling
18try {
19 throw new Error('Database connection failed');
20} catch (error) {
21 logger.error('Connection error', error, {
22 database: 'users'
23 });
24}
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