Protocol Buffers for Node.JS
C++ Protocol Buffer Makefile Python Shell JavaScript Other
Switch branches/tags
Latest commit dd18d55 May 23, 2017 @syndbg syndbg Update README
Add installation instructions for each supported NodeJS version.
Move contribution appreciation to the header of the README.

Node v6.x.x/7.x.x Now Supported

Many thanks to Mário Freitas/imkira for his work. Thanks to work by Nikolai Vavilov/seishun, package uses `node-gyp``, a bundled protobuf lib and compiles on Windows. Currently maintained by Anton Antonov/syndbg.


This is a fork of

Works/worked with NodeJS versions:

  • 0.8.x,
  • 0.10.x,
  • 4.x.x,
  • 5.x.x,
  • 6.x.x,
  • 7.x.x

To install:

# NPM version (may be slightly out-dated, but surely stable)
> npm install protobuf
# 0.8.x/0.10.x support version
> npm install
# 4.x.x/5.x.x support version
> npm install
# 6.x.x/7.x.x support version
> npm install

All the best,


P.S. Breaking change in 0.8.6: uint64 and int64 are now read as Javascript Strings, rather than floating point numbers. They can still be set from Javascript Numbers (as well as from string).

P.P.S. Here's an example I did for - most users won't need the complication of bytes fields.


package com.chrisdew.buftest;

message BufTest {
  optional float num  = 1;
  optional bytes payload = 2;


var fs = require('fs');
var Schema = require('protobuf').Schema;

// "schema" contains all message types defined in buftest.proto|desc.
var schema = new Schema(fs.readFileSync('buftest.desc'));

// The "BufTest" message.
var BufTest = schema['com.chrisdew.buftest.BufTest'];

var ob = { num: 42 };
ob.payload = new Buffer("Hello World");

var proto = BufTest.serialize(ob);
console.log('proto.length:', proto.length);

var outOb = BufTest.parse(proto);
console.log('unserialised:', JSON.stringify(outOb));

var payload = new Buffer(outOb.payload);

Makefile: (second line begins with a TAB not spaces)

    protoc --descriptor_set_out=buftest.desc --include_imports buftest.proto


$ node buftest.js 
proto.length: 18
unserialised: {"num":42,"payload":{"0":72,"1":101,"2":108,"3":108,"4":111,"5":32,"6":87,"7":111,"8":114,"9":108,"10":100,"length":11}}
payload: <Buffer 48 65 6c 6c 6f 20 57 6f 72 6c 64>

Older instructions for use with the NodeJS 0.6.x series.


NodeJS v0.6.X npm

To install on Ubuntu and OSX:

The first steps are to build and install Google's protobuf library. Make sure you have the right version by running "protoc --version" after the install.

tar -xzvf protobuf-2.4.1.tar.gz
cd protobuf-2.4.1/
./configure && make && sudo make install

This installs the npm package.

npm install protobuf

For Ubuntu, update library paths.

sudo ldconfig

For OSX, you might need to add the path:

export DYLD_LIBRARY_PATH=/home/chris/node_modules/protobuf/build/Release:/usr/local/lib:$DYLD_LIBRARY_PATH

And test that it works... Run node, try


you should see:

{ Schema: [Function: Schema] }

As seen from the instructions above, this is my first attempt at packaging a slightly complex C++ module for NPM.

If you can help me simplify these instructions, please submit a patch.

Good luck,