Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
default
✓ import fastifyRedisChannels from 'fastify-redis-channels'
✗ const fastifyRedisChannels = require('fastify-redis-channels')
Default import for ESM; CommonJS require also works but TypeScript might need esModuleInterop.
fastify-redis-channels (plugin)
✓ fastify.register(require('fastify-redis-channels'), { /* options */ })
✗ fastify.use(require('fastify-redis-channels'))
Must use register() as it's a Fastify plugin, not use().
RedisChannelsError
✓ const { RedisChannelsError } = require('fastify-redis-channels')
✗ const RedisChannelsError = require('fastify-redis-channels').RedisChannelsError
Named export for RedisChannelsError; available after registering.
Demonstrates registering the plugin with Redis configuration, producing a message to a channel, and consuming messages using a consumer group.
import fastify from 'fastify';
import fastifyRedisChannels from 'fastify-redis-channels';
const app = fastify();
await app.register(fastifyRedisChannels, {
redis: {
host: process.env.REDIS_HOST || 'localhost',
port: parseInt(process.env.REDIS_PORT || '6379')
}
});
// Produce a message
app.channels.produce('my-channel', { message: 'Hello, world!' });
// Consume messages (as a consumer group)
app.channels.consume('my-channel', 'consumer-group-1', 'consumer-1', async (message) => {
console.log('Received:', message);
});
app.listen({ port: 3000 }, (err) => {
if (err) console.error(err);
});
Errors
Common errors & fixes
Error: REQUEST_TIMEOUT: Redis is unreachable
Redis connection not configured or wrong host/port.
fixSet correct REDIS_HOST and REDIS_PORT environment variables or pass options with correct redis host.
TypeError: Cannot read properties of undefined (reading 'channels')
Plugin not registered before accessing fastify.channels.
fixEnsure app.register(fastifyRedisChannels, ...) is called before any route or decorator that uses channels.
Error: Channel 'my-channel' does not exist
Trying to consume from a channel that hasn't been created yet.
fixCreate the channel by producing a message to it first, or use an option to auto-create channels.
Audit
Dependencies
fastifyrequiredRequired to register as a Fastify plugin; cannot be used standalone.
@hearit-io/redis-channelsrequiredUnderlying implementation of Redis stream channels; options are passed through.
ioredisoptionalUsed for Redis connection; the plugin expects a Redis instance.