From e96e83f5ebbe42a81c94f0774eafbfc1077d319e Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 28 Feb 2017 18:22:02 -0600 Subject: [PATCH] docs/grpc: add additional links to node.js tutorial --- docs/grpc/javascript.md | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/docs/grpc/javascript.md b/docs/grpc/javascript.md index a6af92194..6b1ba094b 100644 --- a/docs/grpc/javascript.md +++ b/docs/grpc/javascript.md @@ -1,6 +1,6 @@ -# How to write a simple lnd client in Javascript using nodejs? +# How to write a simple `lnd` client in Javascript using `node.js -First, you need to initialize a simple nodejs project: +First, you'll need to initialize a simple nodejs project: ``` npm init (or npm init -f if you want to use the default values without prompt) @@ -12,19 +12,22 @@ Then you need to install the Javascript grpc library dependency: npm install grpc --save ``` -You also need to copy the `lnd` `rpc.proto` file in your project directory (or at least somewhere reachable by your Javascript code). +You also need to copy the `lnd` `rpc.proto` file in your project directory (or +at least somewhere reachable by your Javascript code). -The `rpc.proto` file is located in the `lnrpc` directory of the `lnd` sources. - -I had to comment the following line in the `rpc.proto` file otherwise `grpc` would crash: +The `rpc.proto` file is [located in the `lnrpc` directory of the `lnd` +sources](https://github.com/lightningnetwork/lnd/blob/master/lnrpc/rpc.proto). +In order to allow the auto code generated to compile the protos succucsfully, +you'll need to comment out the following line: ``` //import "google/api/annotations.proto"; ``` -Let's now write some Javascript code that simply displays the getinfo command result on the console: +Let's now write some Javascript code that simply displays the `getinfo` command +result on the console: -``` +```js var grpc = require('grpc'); var lnrpcDescriptor = grpc.load("rpc.proto"); @@ -39,7 +42,8 @@ lightning.getInfo({}, function(err, response) { ``` -You just have to lauch your newly created Javascript file `getinfo.js` using `nodejs`: +You just have to lauch your newly created Javascript file `getinfo.js` using +`nodejs`: ``` node getinfo.js @@ -59,4 +63,11 @@ GetInfo: { identity_pubkey: '03c892e3f3f077ea1e381c081abb36491a2502bc43ed37ffb82 testnet: true } ``` -Enjoy! \ No newline at end of file +With the above, you should have all the `lnd` related `gRPC` dependencies +installed locally in your local project. In order to get up to speed with +`protofbuf` usage from Javascript, see [this official `protobuf` reference for +Javascript](https://developers.google.com/protocol-buffers/docs/reference/javascript-generated). +Additionally, [this official gRPC +resource](http://www.grpc.io/docs/tutorials/basic/node.html) details how to +drive `gRPC` from `node.js` including the basics of making RPC calls, streaming +RPC's (bi-directional and uni-directional), etc.