Shailendra Shailendra - 1 year ago 107
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)

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download