I want to use a node.js function on the browser with browserify
. In my code, there is a line as follows:
var x = new Buffer('abc..', 'hex')
However, this causes an error ReferenceError: Buffer is not defined
. I tried to install [buffer-browserify][1]
and include it like this:
var Buffer = require('buffer');
but now I get the error Error: Cannot find module 'buffer'
..
so -how- can I use the Buffer
class in browser javascript?
Thanks for any help,
Update:
In order to build it with browserify
, I created an input.js
file as follows:
var Buffer = require('buffer');
console.log(Buffer);
and I tried to build it with browserify input.js -o output.js
and I included output.js
in my browser code, it prints the Buffer
variable. However, I still get the same error (ReferenceError: Buffer is not defined
) when I try to use it.