Setup guide
Node.js
Send logs from a Node.js app with 30 lines of code and no dependencies.
A tiny logger
No package to install. Save this as logyak.mjs, set LOGYAK_TOKEN (an HTTP source's token) and SERVICE_NAME in the environment, and import logger. Lines are batched and sent every 2 seconds, and a failed send never breaks your app.
logyak.mjs
// logyak.mjs: send logs to Logyak (Node 18+, no dependencies)
const ENDPOINT = 'https://logyak.com/api/v1/logs'
const TOKEN = process.env.LOGYAK_TOKEN // an HTTP source token
const SERVICE = process.env.SERVICE_NAME ?? 'app'
let queue = []
async function flush() {
if (!queue.length || !TOKEN) return
const body = queue.map(l => JSON.stringify(l)).join('\n')
queue = []
try {
await fetch(ENDPOINT, { method: 'POST', headers: { Authorization: `Bearer ${TOKEN}`, 'Content-Type': 'application/x-ndjson' }, body })
} catch { /* never let logging break the app */ }
}
setInterval(flush, 2000).unref()
process.on('beforeExit', flush)
function log(level, message, attrs = {}) {
queue.push({ timestamp: new Date().toISOString(), level, service: SERVICE, message, ...attrs })
if (queue.length >= 500) void flush()
}
export const logger = {
debug: (m, a) => log('debug', m, a),
info: (m, a) => log('info', m, a),
warn: (m, a) => log('warn', m, a),
error: (m, a) => log('error', m, a),
flush,
}
// Usage:
// import { logger } from './logyak.mjs'
// logger.error('Payment failed', { order_id: 42, request_id: req.id })Already using pino?
pino writes one JSON object per line with a numeric level (30 info, 40 warn, 50 error), time and msg, which Logyak reads as they are. Pipe its output to the HTTP API, or run the app on Railway, Vercel or Render and connect that platform instead.