{"id":15391,"library":"syslog-server","title":"Node.js Syslog Server","description":"syslog-server is a lightweight Node.js library for creating a server to receive syslog messages over UDP. It provides a simple, event-driven API to start, stop, and manage the syslog listener. The library, currently at version 1.0.1, allows configuration of the listening port and address, and emits 'message' events for each incoming syslog packet. Each message event provides parsed details such as the reception date, originating host IP, IP protocol version (IPv4/IPv6), and the raw syslog message content. While it does not specify adherence to particular syslog RFCs for deep message parsing, it offers a foundational layer for applications needing to collect basic syslog data. Its primary differentiator is its minimal footprint and direct use of Node.js's built-in `dgram` module, making it suitable for simple syslog collection setups.","status":"active","version":"1.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/guithess/syslog-server","tags":["javascript","syslog","syslog-server"],"install":[{"cmd":"npm install syslog-server","lang":"bash","label":"npm"},{"cmd":"yarn add syslog-server","lang":"bash","label":"yarn"},{"cmd":"pnpm add syslog-server","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is CommonJS-first. Direct ESM `import` statements are not supported without a transpiler or custom configuration, and will likely result in runtime errors. Stick to `require()`.","wrong":"import SyslogServer from 'syslog-server';","symbol":"SyslogServer","correct":"const SyslogServer = require('syslog-server');"},{"note":"The core functionality relies on event listeners for 'message', 'start', 'stop', and 'error'. Ensure you register event handlers before calling `server.start()` to avoid missing initial events.","symbol":"server.on('message', ...)","correct":"server.on('message', (value) => { /* handle message */ });"},{"note":"While `start` accepts an optional callback, it primarily returns a Promise for modern async/await patterns. Prefer Promise-based handling for better error propagation and readability.","wrong":"server.start(options, callback);","symbol":"server.start","correct":"server.start().then(() => console.log('Server started')).catch(err => console.error(err));"}],"quickstart":{"code":"const SyslogServer = require('syslog-server');\nconst server = new SyslogServer();\n\nserver.on('message', (value) => {\n    console.log(`Received message from ${value.host} (${value.protocol}) at ${value.date.toISOString()}:`);\n    console.log(value.message);\n});\n\nserver.on('start', () => {\n    console.log('Syslog server started on port 514');\n});\n\nserver.on('error', (err) => {\n    console.error('Syslog server error:', err.message);\n});\n\n// Start the server, potentially on a different port if 514 is privileged or in use\nserver.start({\n    port: process.env.SYSLOG_PORT ? parseInt(process.env.SYSLOG_PORT, 10) : 514,\n    address: '0.0.0.0'\n}).catch(err => {\n    console.error('Failed to start syslog server:', err.message);\n    process.exit(1);\n});\n\n// To stop the server gracefully on process exit\nprocess.on('SIGINT', async () => {\n    console.log('Shutting down syslog server...');\n    await server.stop();\n    console.log('Syslog server stopped.');\n    process.exit(0);\n});","lang":"javascript","description":"This quickstart initializes a syslog server, logs incoming messages to the console, and includes basic error handling and graceful shutdown."},"warnings":[{"fix":"Run your Node.js application with `sudo` (not recommended for production) or configure your system to allow the Node.js process to bind to privileged ports without root, or choose a non-privileged port (e.g., >1024) for the syslog server.","message":"The default port 514 is a privileged port on Unix-like systems. Running the server on this port often requires elevated permissions (e.g., `sudo`) or configuring system capabilities.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use the CommonJS `require()` syntax: `const SyslogServer = require('syslog-server');`. If you must use ESM, consider a transpilation step or a wrapper module that explicitly exports it for ESM consumption.","message":"This package primarily uses Node.js CommonJS modules (`require`). Attempting to use `import` statements directly will result in a `TypeError: SyslogServer is not a constructor` or similar import errors.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"If advanced syslog message parsing (e.g., extracting facility, severity, timestamp from the message string) is required, integrate a dedicated syslog message parsing library or implement custom regex-based parsing on `value.message`.","message":"The library captures the raw syslog message (`value.message`) but does not explicitly mention parsing according to specific RFCs (e.g., RFC 3164, RFC 5424). Users expecting structured data beyond the raw message should implement their own parsing logic.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Run your Node.js application with administrative privileges (e.g., `sudo node app.js`) or configure a non-privileged port (e.g., `server.start({ port: 10514 })`).","cause":"The application is trying to bind to a privileged port (514) without sufficient permissions.","error":"Error: listen EACCES: permission denied 0.0.0.0:514"},{"fix":"Change the import statement to `const SyslogServer = require('syslog-server');`.","cause":"Attempting to use `import SyslogServer from 'syslog-server'` with a CommonJS-only package.","error":"TypeError: SyslogServer is not a constructor"},{"fix":"Ensure no other syslog server or application is running on the same port. Use `netstat -tulnp | grep 514` (Linux) or `lsof -i :514` (macOS) to identify the conflicting process, then terminate it or choose a different port for your `syslog-server` instance.","cause":"Another process is already listening on the specified IP address and port.","error":"Error: listen EADDRINUSE: address already in use 0.0.0.0:514"}],"ecosystem":"npm"}