AI & Agents

How to Handle Fastio Realtime Events with Node.js Express

Handle Fastio real-time file notifications in Node.js Express using WebSocket feeds and activity polling. Build reactive agent architectures without webhooks. This guide covers prerequisites, Express server setup, WebSocket event streaming, local development, and production best practices.

Fastio Editorial Team 6 min read
Real-time file notifications in Express apps

What Are Fastio Realtime Event Feeds?

Fastio provides a WebSocket events feed and a realtime activity feed that can be polled via the REST API at https://api.fast.io/current/. Instead of webhooks, your application connects directly to receive events when files are uploaded, modified, deleted, or shared.

Each payload includes an event object with details like event ID, event type, created timestamp, workspace ID, and file metadata.

Streaming events over WebSockets or polling the activity feed ensures your server stays reactive while remaining securely behind your firewall without exposing public endpoints.

Refer to the Fastio documentation and REST API for payload schemas and activity polling endpoints.

Fastio event log with realtime notifications

What to check before scaling Fastio event handling with Node.js Express

To handle Fastio real-time events with Node.js Express, prepare these prerequisites:

Fastio Account:

  • Sign up for the Fastio Business Trial (14-day trial, card required).
  • Create a workspace.
  • Generate an API key from your account settings.

Development Environment:

  • Node.js 18 or later.
  • Project initialization:
mkdir fastio-events-express
cd fastio-events-express
npm init -y
npm install express ws dotenv axios

Create .env:

FASTIO_API_KEY=your_actual_api_key_here
PORT=3000
Fastio features

Give Your AI Agents Persistent Storage

Get real-time file events in your Node.js Express apps. The 14-day Business Trial provides access to workspaces, shares, and activity feeds.

Connecting Fastio Realtime Feeds to Express Apps

Build a secure Express service that maintains an outbound WebSocket connection to Fastio's events stream.

Create index.js:

const express = require('express');
const WebSocket = require('ws');
require('dotenv').config();

const app = express();
const port = process.env.PORT || 3000;
const apiKey = process.env.FASTIO_API_KEY;

app.use(express.json());

// Connect to Fastio WebSocket events feed
function connectEvents() {
  const ws = new WebSocket('wss://api.fast.io/current/events', {
    headers: { Authorization: `Bearer ${apiKey}` }
  });

ws.on('open', () => {
    console.log('Connected to Fastio events feed');
  });

ws.on('message', (data) => {
    try {
      const event = JSON.parse(data);
      console.log(`Event received: ${event.event_type} on ${event.resource?.name || 'resource'}`);
      // Route event to processing logic or AI agents
    } catch (err) {
      console.error('Error parsing event:', err);
    }
  });

ws.on('close', () => {
    console.log('Connection closed. Reconnecting in 5s...');
    setTimeout(connectEvents, 5000);
  });
}

connectEvents();

app.get('/health', (req, res) => {
  res.json({ status: 'ok' });
});

app.listen(port, () => {
  console.log(`Express server running on port ${port}`);
});

This establishes an event listener without exposing public inbound webhook endpoints.

Frequently Asked Questions

How does Fastio stream real-time workspace events?

Fastio provides a WebSocket events feed for push streaming and a realtime activity feed via the REST API, avoiding the need for inbound webhooks.

How do you listen to Fastio events in Node.js Express?

Use a WebSocket client like 'ws' inside your Node.js application to connect to Fastio's WebSocket events endpoint and handle incoming file notifications.

Do I need ngrok to test Fastio events on localhost?

No. Because your Node.js application initiates an outbound connection to Fastio's WebSocket feed, you can test on localhost without using ngrok or opening firewall ports.

How do I handle network interruptions?

Listen for the WebSocket 'close' event and reconnect with exponential backoff. You can query Fastio's activity feed to fetch any events that occurred while disconnected.

Related Resources

Fastio features

Give Your AI Agents Persistent Storage

Get real-time file events in your Node.js Express apps. The 14-day Business Trial provides access to workspaces, shares, and activity feeds.