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.
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
TypeError: Buffer.alloc is not a function, requires Node v4.5.0
node.js - npm ERR! Buffer.alloc is not a function - Stack Overflow
`Buffer.alloc` is not a function
node.js - TypeError: Buffer.alloc is not a function while accessing firebase tools - Stack Overflow
Reading your console output, the return value of require("buffer") is not a function. Instead, it's an object that has two methods: Buffer and SlowBuffer.
In your case, Buffer is that object with those two methods. You should instead do var Buffer = require('buffer').Buffer; (assuming you don't also need SlowBuffer).
As noted in another answer, you don't even need to require("buffer"). It is automatically available as a global in Node.
From the NodeJS documentation:
The Buffer class is a global, making it very rare that one would need to ever require('buffer').
Your code works for me if I remove the var Buffer = require('buffer') line.
It looks like when you do require buffer, the Buffer var is an object that contains the Buffer constructor, so that new Buffer.Buffer(doc["filedata"], 'base64')); also works.