How to convert AQMP message buffer into JSON object when using node.js amqp module?

node-amqp, node.js, type-conversion

Solution

message.data.toString() returned the appropriate JSON string.

Problem

I am using node.js amqp module for reading messages from a queue. The following is the callback that is invoked when there is a message available on the queue: ``` function onMessage(message, headers, deliveryInfo) { console.log(message); //This prints buffer //how to convert message (which I expect to be JSON) into a JSON object. //Also how to get the JSON string from the 'message' which seems to be a buffer } ``` Thanks.

Original source