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.
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.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With