Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js, Protocol buffers and ubuntu - How to get it to work?

Here are the steps I used to try and load a proto file in node.js. Overall, how do I get protocol buffers to work with node.js?

1) Dowloaded and installed protocol buffers into this location.

/home/ubuntu/Downloads/protobuf-2.4.1

2) Downloaded this protobuf-for-node fix from this repo. I places the folder in the node_modules folder of my node.js app folder.

git://github.com/pzgz/protobuf-for-node.git

3) Ran the following command

cd node_modules/protobuf-for-node
PROTOBUF=~/Downloads/protobuf-2.4.1 /usr/local/bin/node-waf configure clean build

4) Moved the following files to these locations:

cp node_modules/protobuf-for-node/protobuf_for_node.h /usr/local/include/node
cp node_modules/protobuf-for-node/build/Release/protobuf_for_node_lib.so /usr/local/lib

5) Ran the following to build the feeds.proto example that ships with node.js

cd node_modules/protobuf-for-node/example
protoc --descriptor_set_out=feeds.desc --include_imports feeds.proto

6) In the app, I added this line.

var express = require('express'), routes = require('./routes');
var fs = require('fs');
var puts = require('util').puts;
url = require('url');
moment = require('moment');
var uuid = require('node-uuid');
var app = module.exports = express.createServer();
var Schema = require('protobuf_for_node').Schema;
var schema = new Schema(fs.readFileSync('/home/ubuntu/workspace/rtbopsConfig/rtbServers/rtbNodejsServer/node_modules/protobuf-for-node/example/feeds.desc'));

7) Here is my error.

module.js:337
    throw new Error("Cannot find module '" + request + "'");
          ^
Error: Cannot find module 'protobuf_for_node'
    at Function._resolveFilename (module.js:337:11)
    at Function._load (module.js:279:25)
    at Module.require (module.js:359:17)
    at require (module.js:375:17)
    at Object.<anonymous> (/home/ubuntu/app.js:9:14)
    at Module._compile (module.js:446:26)
    at Object..js (module.js:464:10)
    at Module.load (module.js:353:31)
    at Function._load (module.js:311:12)
    at Array.0 (module.js:484:10)
like image 390
Tampa Avatar asked Nov 22 '25 11:11

Tampa


1 Answers

Consider using this fork of the library instead:

https://github.com/chrisdew/protobuf/

It seems to be more actively maintained and has better documentation. Installing it was npm was trivial and doing a require('protobuf') is working fine for me.

For Ubuntu I needed to install the following to get the package installed with npm and get the proto file compiled:

sudo apt-get install libprotobuf-dev protobuf-compiler

It looks like you already have those but installed them by hand.

like image 111
Jeff Hiltz Avatar answered Nov 23 '25 23:11

Jeff Hiltz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!