Node.js
Send an authenticated event using the template example.
Prepare the environment
Set LOGSTASH_URL and LOGSTASH_PASSWORD as described in Sending data. Run inside the same Railway environment as Logstash.
Example
Source: examples/node/send.mjs in the template repository. The code below is identical to that file.
const { LOGSTASH_URL: url, LOGSTASH_PASSWORD: password } = process.env;
if (!url || !password) {
console.error('Set LOGSTASH_URL and LOGSTASH_PASSWORD');
process.exit(1);
}
try {
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Basic ${Buffer.from(`shipper:${password}`).toString('base64')}`,
},
body: JSON.stringify({
message: 'hello from Node', service: 'example-node', level: 'info',
attributes: { language: 'node' },
}),
signal: AbortSignal.timeout(10000),
redirect: 'error',
});
if (!response.ok) throw new Error(`Intake returned HTTP ${response.status}`);
console.log('Event accepted. Confirm indexing in Kibana.');
} catch {
console.error('Send failed. Check connectivity and intake credentials.');
process.exit(1);
}Run and verify
From the template repository:
node examples/node/send.mjsSearch service : "example-node" in Kibana's elk-logs data view. Widen the time range if needed. The program's timeout is configured in the source above. A successful exit confirms acceptance; finding the event confirms indexing.
The template CI uses Node 22, Python 3.12, and Go 1.23. These are selected test runtimes, not minimum supported versions. The Node example requires built-in fetch and AbortSignal.timeout.
Failure behavior
Missing variables, rejected credentials, redirects, and connection errors cause failure. There is no automatic retry. A retry after a timeout may duplicate an event. Do not log the password when debugging.