tree: 48230c732887959fd5780dac7b95f772290dc2a2
  1. BUILD.bazel
  2. client.js
  3. README.md
  4. server.js
node/example/routeguide/README.md

Node module structure:

The first consideration is that of the generated _pb_grpc.js file (and all imports in general). In this case the protocol compiler emit this require statement: var example_proto_routeguide_pb = require('../../example/proto/routeguide_pb.js');. So, we need to build a node_module that contains both the _pb.js and _grpc_pb.js file AND satisfies the require paths.

These are the 2 files:

bazel-genfiles/node/example/routeguide/routeguide_pb/example/proto/routeguide_pb.js
bazel-genfiles/node/example/routeguide/routeguide_pb/example/proto/routeguide_grpc_pb.js

Therefore, we need a node_module or eqivalent with an index.js file in bazel-genfiles/node/example/. The index.js should have the content:

module.exports = {
    'routeguide_pb': require('./routeguide/routeguide_pb/example/proto/routeguide_pb.js'),
    'routeguide_grpc_pb': require('./routeguide/routeguide_pb/example/proto/routeguide_grpc_pb.js'),
}

And it should have a subdirectory routeguide/routeguide_pb/ that contains the files.

Location of the generated node_module_index file index.js is arbitrary since it gets copied to node_module root as it is the index = attribute.