Shailendra
Shailendra

Reputation: 367

In node.js, Buffer.from() method is throwing "ascii is not a function" error

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');

Exception

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

Upvotes: 1

Views: 1590

Answers (1)

mscdex
mscdex

Reputation: 106736

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.

Upvotes: 2

Related Questions