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.
KafkaRest
✓ const KafkaRest = require('kafka-rest')
✗ import KafkaRest from 'kafka-rest'
Uses CommonJS; no default ES export. Use require.
default
✓ const KafkaRest = require('kafka-rest')
✗ const { KafkaRest } = require('kafka-rest')
Library exports single constructor as module.exports.
(none)
✓ const kafka = new KafkaRest({ url: 'http://localhost:8082' })
✗ new KafkaRest('http://localhost:8082')
Config must be an object with url property.
Initialize client, list topics, produce a message, and consume messages from a consumer group.
const KafkaRest = require('kafka-rest');
const kafka = new KafkaRest({ url: process.env.KAFKA_REST_URL ?? 'http://localhost:8082' });
// List topics
kafka.topics.list((err, topics) => {
if (err) console.error(err);
else topics.forEach(t => console.log('Topic:', t.raw));
});
// Produce a message
kafka.topic('test').produce('hello world', (err, res) => {
if (err) console.error(err);
else console.log('Produced:', res);
});
// Consume using a consumer group
const consumer = kafka.consumer('my-group');
consumer.join('test', (err) => {
if (err) console.error(err);
else consumer.consume((err, msgs) => {
if (err) console.error(err);
else msgs.forEach(m => console.log('Msg:', m.value));
});
});
Errors
Common errors & fixes
TypeError: kafka.topics.list is not a function
Using ES import or destructuring incorrectly
fixUse const KafkaRest = require('kafka-rest'); then new KafkaRest({...}) Error: connect ECONNREFUSED 127.0.0.1:8082
Kafka REST Proxy not running or wrong URL
fixStart the proxy or set KAFKA_REST_URL environment variable to correct endpoint.
TypeError: kafka.topic(...).produce is not a function
Incomplete topic object without metadata
fixUse kafka.topic('test', callback) to fetch first, or use kafka.topics.topic('test').produce() Audit
Dependencies
asyncrequiredused for control flow in library internals