Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: Buffer.alloc is not a function

Tags:

node.js

From node docs, I am trying some code from Buffer .

When I execute this statement

const buf = Buffer.from('hello world', 'ascii');

it throws an exception: TypeError: Buffer.alloc is not a function

My node version is v5.7.1.

I don't understand why?

Here is the error screen.

enter image description here

like image 362
RIYAJ KHAN Avatar asked Apr 08 '16 12:04

RIYAJ KHAN


3 Answers

The new Buffer API is only available in v5.10.0+, so you'll need to upgrade to use it.

If you want to view the docs for v5.7.1, you can go here.

FWIW the new Buffer API is also now available in node v4.x as of v4.5.0.

like image 53
mscdex Avatar answered Nov 10 '22 13:11

mscdex


This error occurs due to missmatch node version so please node version on my machine like this:

sudo npm cache clean -f
sudo npm install -g n
sudo n stable
like image 44
Pankaj Chauhan Avatar answered Nov 10 '22 15:11

Pankaj Chauhan


if you can do these commands,it should be work.

step 1:

first, you can type this command sudo npm cache clean -f

step 2: Now,you can type this command sudo npm install -g n

step 3:

Now ,you should enter this command sudo n 6.4.0

step 4:

finally, you should enter this command for restart the your system or reboot

shutdown -h now

like image 1
Muthuramalingam Duraipandi Avatar answered Nov 10 '22 15:11

Muthuramalingam Duraipandi