I want to delete all the topics present in kafka using kafka-node but admin.deleteTopic() or admin.deleteTopic() , both are not working giving it is not defined.
I'm expecting to a js file by running that I can delete all the kafka-topics present using kafka-node V5.0.0
I'm using following code:
const kafka = require('kafka-node');
const client = new kafka.KafkaClient({ kafkaHost: 'localhost:9093,localhost:9094' });
const admin = new kafka.Admin(client);
admin.listTopics((err, res) => {
if (err) {
console.error(err);
return;
}
const topicsToDelete = Object.keys(res[1].metadata)
console.log(topicsToDelete);
admin.deleteTopics({ topics: topicsToDelete }, (err, res) => {
if (err) {
console.error(err);
return;
}
console.log('Topics deleted:', res);
});
});