noodown-fastify
v1.0.4
Published
Observability middleware for fastify that sends HTTP request logs to the noodown.com service.
Downloads
434
Maintainers
Readme
noodown-fastify
Observability plugin for Fastify that sends HTTP request logs to the Noodown service.
Installation
npm install noodown-fastifyRequirements
- Node.js >= 18.0.0
- Fastify >= 5.6.2
Configuration
Before using the plugin, you need to configure the SERVER_KEY environment variable with your Noodown server key.
Using dotenv
Create a .env file in your project root:
SERVER_KEY=your_key_hereThe plugin automatically loads environment variables using dotenv.
Usage
import Fastify from 'fastify';
import observabilityRoutes from 'noodown-fastify';
const app = Fastify();
// Register the observability plugin
app.addHook('onRequest', observabilityRoutes);
// Your routes here
app.get('/', async (request, reply) => {
return { hello: 'world' };
});
app.listen({ port: 3000 }, (err, address) => {
if (err) {
console.error(err);
process.exit(1);
}
console.log(`Server running at ${address}`);
});Collected Data
The plugin automatically collects the following data from each request:
- method: HTTP method (GET, POST, etc.)
- path: Request path
- status: HTTP response status code
- duration_ms: Request duration in milliseconds
- timestamp: Request date and time (ISO 8601)
- client_ip: Client IP (extracted from headers like
x-forwarded-for,x-real-ip, etc.) - user_agent: Client user agent
- origin: Origin header
- referer: Referer header
- host: Host header
- content_type: Request Content-Type
How It Works
- The
onRequesthook is executed before each request - Records the start time using
process.hrtime.bigint() - When the response is finalized (
closeevent), builds the log with all data - Sends the log asynchronously to the Noodown API using
fetchwithkeepalive: true - Does not block the request response (errors are silently ignored)
Viewing and Analyzing Data
To view and analyze the collected data, you need to:
- Register an account at noodown.com
- Log in to the dashboard
- Access your logs and analytics in the dashboard
License
MIT
