8000 Use `Buffer.from` in place of `new Buffer` · zerolugithub/rabbitmq-tutorials@f71200b · GitHub
[go: up one dir, main page]

Skip to content

Commit f71200b

Browse files
authored
Use Buffer.from in place of new Buffer
Node has [deprecated](https://nodejs.org/api/buffer.html#buffer_class_buffer) the use of `new Buffer()` as of v6.0.0 and has assigned it a stability score of 0. The Javascript tutorial should utilize [`Buffer.from`](https://nodejs.org/api/buffer.html#buffer_class_method_buffer_from_str_encoding) instead, which was introduced in v5.10.0. Specifically, the [message sending example](https://www.rabbitmq.com/tutorials/tutorial-one-javascript.html) with this line: `ch.sendToQueue(q, new Buffer('Hello World!'));` should be updated to: `ch.sendToQueue(q, Buffer.from('Hello World!'));`
1 parent 31fe04e commit f71200b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

javascript-nodejs/src/send.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ amqp.connect('amqp://localhost', function(err, conn) {
88
var msg = 'Hello World!';
99

1010
ch.assertQueue(q, {durable: false});
11-
ch.sendToQueue(q, new Buffer(msg));
11+
ch.sendToQueue(q, Buffer.from(msg));
1212
console.log(" [x] Sent %s", msg);
1313
});
1414
setTimeout(function() { conn.close(); process.exit(0) }, 500);

0 commit comments

Comments
 (0)
0