Are you happy with your logging solution? Would you help us out by taking a 30-second survey? Click here


Protocol Buffers for Node.js

Subscribe to updates I use protocol-buffers

Statistics on protocol-buffers

Number of watchers on Github 553
Number of open issues 25
Average time to close an issue about 1 month
Main language JavaScript
Average time to merge a PR 2 days
Open pull requests 6+
Closed pull requests 3+
Last commit over 1 year ago
Repo Created over 5 years ago
Repo Last Updated over 1 year ago
Size 149 KB
Organization / Authormafintosh
Page Updated
Do you use protocol-buffers? Leave a review!
View open issues (25)
View protocol-buffers activity
View on github
Fresh, new opensource launches 🚀🚀🚀
Trendy new open source projects in your inbox! View examples

Subscribe to our mailing list

Evaluating protocol-buffers for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)


Protocol Buffers for Node.js

npm install protocol-buffers

build status dat


Assuming the following test.proto file exists

enum FOO {
  BAR = 1;

message Test {
  required float num  = 1;
  required string payload = 2;

message AnotherOne {
  repeated FOO list = 1;

Use the above proto file to encode/decode messages by doing

var protobuf = require('protocol-buffers')

// pass a proto file as a buffer/string or pass a parsed protobuf-schema object
var messages = protobuf(fs.readFileSync('test.proto'))

var buf = messages.Test.encode({
  num: 42,
  payload: 'hello world'

console.log(buf) // should print a buffer

To decode a message use Test.decode

var obj = messages.Test.decode(buf)
console.log(obj) // should print an object similar to above

Enums are accessed in the same way as messages

var buf = messages.AnotherOne.encode({
  list: [

Nested emums are accessed as properties on the corresponding message

var buf = message.SomeMessage.encode({
  list: [

See the Google Protocol Buffers docs for more information about the available types etc.

Compile to a file

Since v4 you can now compile your schemas to a JavaScript file you can require from Node. This means you do not have runtime parse the schemas, which is useful if using in the browser or on embedded devices. It also makes the dependency footprint a lot smaller.

# first install the cli tool
npm install -g protocol-buffers

# compile the schema
protocol-buffers test.proto -o messages.js

# then install the runtime dependency in the project
npm install --save protocol-buffers-encodings

That's it! Then in your application you can simply do

var messages = require('./messages')

var buf = messages.Test.encode({
  num: 42


This module is fast.

It uses code generation to build as fast as possible encoders/decoders for the protobuf schema. You can run the benchmarks yourself by doing npm run bench.

On my Macbook Air it gives the following results

Benchmarking JSON (baseline)
  Running object encoding benchmark...
  Encoded 1000000 objects in 2142 ms (466853 enc/s)

  Running object decoding benchmark...
  Decoded 1000000 objects in 970 ms (1030928 dec/s)

  Running object encoding+decoding benchmark...
  Encoded+decoded 1000000 objects in 3131 ms (319387 enc+dec/s)

Benchmarking protocol-buffers
  Running object encoding benchmark...
  Encoded 1000000 objects in 2089 ms (478698 enc/s)

  Running object decoding benchmark...
  Decoded 1000000 objects in 735 ms (1360544 dec/s)

  Running object encoding+decoding benchmark...
  Encoded+decoded 1000000 objects in 2826 ms (353857 enc+dec/s)

Note that JSON parsing/serialization in node is a native function that is really fast.

Leveldb encoding compatibility

Compiled protocol buffers messages are valid levelup encodings. This means you can pass them as valueEncoding and keyEncoding.

var level = require('level')
var db = level('db')

db.put('hello', {payload:'world'}, {valueEncoding:messages.Test}, function(err) {
  db.get('hello', {valueEncoding:messages.Test}, function(err, message) {



protocol-buffers open issues Ask a question     (View All Issues)
  • over 3 years Streams support?
  • over 3 years encoding an out-of-range integer results in a corrupt message
  • over 3 years Negative int32 values are not decoded properly.
  • over 3 years Enum Translations
  • over 3 years Unknown wire type: 6
  • over 3 years imports is non-functional
  • over 3 years represent bigints in a safe way
  • almost 4 years Cannot reference type with package name
  • almost 4 years Support for ascii protobuf representation
  • almost 4 years The library should throw if a repeated field with non-primitive type is provided with [packed=true]
  • over 4 years Could not resolve message field imported
  • over 4 years negative int64 values handling is not compatible with reference Protobuf encoding
  • over 4 years "Error: Unexpected token: " when parsing empty schema file
  • almost 5 years Handling of default values
  • almost 5 years "Offline" interface precompilation
  • almost 5 years Use closures instead of genfun?
  • almost 5 years Doesn't support group in protocol definition
protocol-buffers open pull requests (View All Pulls)
  • Add option to support null as default value
  • Implements import syntax.
  • Add option to support null as default value
  • Updated default value handling for optional fields
  • Fixed protobuf imports with respect to root_dir
  • use bytebuffers package to work with int64 numbers
protocol-buffers questions on Stackoverflow (View All Questions)
  • Dumping protocol-buffers file to stdout to debug/investigate?
  • Scala protocol buffers compiler
  • Does REST supports protocol buffers
  • Generate both Java and Scala classes using Protocol Buffers in ScalaPB
  • spring mvc rest protocol buffers http 406 not acceptable error
  • Serializing/Deserializing a standalone integer using protocol buffers
  • Is there a definitive *nix command line tool for inspecting protocol buffers?
  • Protocol Buffers in Java: can we handle primitive arrays efficiently?
  • Google Cloud Datastore with and w/o Protocol Buffers
  • Protocol buffers inheritance
  • Biggest differences of Thrift vs Protocol Buffers?
  • Cleanly handling encrypted data in protocol buffers or similar
  • Google Protocol Buffers Vs JSON: C++ to C# communication
  • Which Node.js module should I install to be able to use google protocol buffers?
  • How to use protocol buffers?
  • Setting value of a nested, non-repeating Protocol Buffers message in Python
  • Google Protocol Buffers - JavaScript
  • Why is Protocol Buffers so much better than .NET binary serialization?
  • Is there a Protocol Buffers binding for Codegear C++ Builder 2007?
  • Parsing Protocol Buffers, written in Java and read in Python
  • Wire protocol buffers vs Cap'n proto - which one is better?
  • Parsing Protocol-Buffers without knowing the .proto
  • Are there C++ equivalents for the Protocol Buffers delimited I/O functions in Java?
  • ASP.NET WebApi with Protocol Buffers - Error handling
  • Is there a standard mapping between JSON and Protocol Buffers?
  • Protocol buffers, where to use them?
  • Are there any applications currently offering a Protocol Buffers API?
  • How to handle the generic type Object with protocol buffers, in the .proto file?
  • Pants: Generate Python from Protocol Buffers
  • Spring MVC 4 REST with protocol buffers not working
protocol-buffers list of languages used
Other projects in JavaScript