Node.js — Winston Transport

The @loginformant/node npm package provides a Winston transport and a standalone logger for any Node.js app — Express, Next.js, NestJS, or plain scripts.

1 Install
bash
npm install @loginformant/node winston
2 Add the transport to your Winston logger
javascript — logger.js
const winston = require('winston');
const { LogInformantTransport } = require('@loginformant/node');

const logger = winston.createLogger({
  level: 'info',
  transports: [
    new winston.transports.Console(),
    new LogInformantTransport({
      apiUrl: 'https://app.loginformant.com',
      apiKey: process.env.LOGINFORMANT_API_KEY,
    }),
  ],
});

module.exports = logger;
typescript — logger.ts
import winston from 'winston';
import { LogInformantTransport } from '@loginformant/node';

export const logger = winston.createLogger({
  level: 'info',
  transports: [
    new winston.transports.Console(),
    new LogInformantTransport({
      apiUrl: 'https://app.loginformant.com',
      apiKey: process.env.LOGINFORMANT_API_KEY!,
    }),
  ],
});
3 Log in your app
javascript — Express example
const express = require('express');
const logger = require('./logger');

const app = express();

app.get('/orders/:id', (req, res) => {
  logger.info('Order viewed', { orderId: req.params.id, userId: req.user?.id });

  try {
    // your logic
    res.json({ ok: true });
  } catch (err) {
    logger.error('Failed to load order', { orderId: req.params.id, error: err.message });
    res.status(500).json({ error: 'Internal error' });
  }
});

app.listen(3000);
4 Set your API key

Store the key in an environment variable — never hardcode it:

bash — .env
LOGINFORMANT_API_KEY=your-api-key-here
Use dotenv in development to load .env files automatically: npm install dotenv and add require('dotenv').config() at the top of your entry file.

Standalone logger (no Winston dependency)

If you don't use Winston, import LogInformantLogger directly — no peer dependencies required:

javascript
const { LogInformantLogger } = require('@loginformant/node');

const log = new LogInformantLogger({
  apiUrl: 'https://app.loginformant.com',
  apiKey: process.env.LOGINFORMANT_API_KEY,
});

log.info('Server started', { port: 3000 });
log.warn('Cache miss', { key: 'user:42' });
log.error('Database connection failed', { host: 'db.internal' });

Configuration options

OptionDefaultDescription
apiUrlrequiredYour LogInformant instance URL
apiKeyrequiredApplication API key
batchSize50Max logs per HTTP request
flushIntervalMs2000How often to flush (milliseconds)

Log level mapping

WinstonLogInformant
silly / verboseDebug
debugDebug
infoInformation
warnWarning
errorError