Shailendra Shailendra - 9 months ago 49
Node.js Question

In node.js, Buffer.from() method is throwing error. Please help me understand what I am doing wrong here

In Node.js,Buffer class is global. When I am trying to execute below line of code in visual studio code, node.js is throwing exception.

My Code
var buffer = Buffer.from('Hello','ascii');


TypeError: ascii is not a function
at Function.from (native)
at Function.from (native)


The Buffer.from() you're seeing is actually ArrayBuffer.from() which has different behavior. Fortunately for LTS users, node v4.5.0 was recently released which does include the new node Buffer APIs (including the custom Buffer.from()). Also, node v6.x (which will become the next LTS branch in October) has had these APIs for awhile now.