forked from grpc/grpc
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace Node example files with references to the new location
- Loading branch information
1 parent
32a46a9
commit 0381846
Showing
22 changed files
with
22 additions
and
4,117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1 @@ | ||
gRPC in 3 minutes (Node.js) | ||
=========================== | ||
|
||
PREREQUISITES | ||
------------- | ||
|
||
- `node`: This requires Node 0.12.x or greater. | ||
|
||
INSTALL | ||
------- | ||
|
||
```sh | ||
$ # Get the gRPC repository | ||
$ export REPO_ROOT=grpc # REPO root can be any directory of your choice | ||
$ git clone -b RELEASE_TAG_HERE https://github.com/grpc/grpc $REPO_ROOT | ||
$ cd $REPO_ROOT | ||
|
||
$ cd examples/node | ||
$ npm install | ||
``` | ||
|
||
TRY IT! | ||
------- | ||
|
||
There are two ways to generate the code needed to work with protocol buffers in Node.js - one approach uses [Protobuf.js](https://github.com/dcodeIO/ProtoBuf.js/) to dynamically generate the code at runtime, the other uses code statically generated using the protocol buffer compiler `protoc`. The examples behave identically, and either server can be used with either client. | ||
|
||
- Run the server | ||
|
||
```sh | ||
$ # from this directory | ||
$ node ./dynamic_codegen/greeter_server.js & | ||
$ # OR | ||
$ node ./static_codegen/greeter_server.js & | ||
``` | ||
|
||
- Run the client | ||
|
||
```sh | ||
$ # from this directory | ||
$ node ./dynamic_codegen/greeter_client.js | ||
$ # OR | ||
$ node ./static_codegen/greeter_client.js | ||
``` | ||
|
||
TUTORIAL | ||
-------- | ||
You can find a more detailed tutorial in [gRPC Basics: Node.js][] | ||
|
||
[Install gRPC Node]:../../src/node | ||
[gRPC Basics: Node.js]:https://grpc.io/docs/languages/node/basics | ||
These examples have been moved to [the grpc/grpc-node repository](https://github.com/grpc/grpc-node/tree/master/examples). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
This is the dynamic code generation variant of the Node examples. Code in these examples is generated at runtime using Protobuf.js. | ||
These examples have been moved to [the grpc/grpc-node repository](https://github.com/grpc/grpc-node/tree/master/examples). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1 @@ | ||
/* | ||
* | ||
* Copyright 2015 gRPC authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
var PROTO_PATH = __dirname + '/../../protos/helloworld.proto'; | ||
|
||
var parseArgs = require('minimist'); | ||
var grpc = require('@grpc/grpc-js'); | ||
var protoLoader = require('@grpc/proto-loader'); | ||
var packageDefinition = protoLoader.loadSync( | ||
PROTO_PATH, | ||
{keepCase: true, | ||
longs: String, | ||
enums: String, | ||
defaults: true, | ||
oneofs: true | ||
}); | ||
var hello_proto = grpc.loadPackageDefinition(packageDefinition).helloworld; | ||
|
||
function main() { | ||
var argv = parseArgs(process.argv.slice(2), { | ||
string: 'target' | ||
}); | ||
var target; | ||
if (argv.target) { | ||
target = argv.target; | ||
} else { | ||
target = 'localhost:50051'; | ||
} | ||
var client = new hello_proto.Greeter(target, | ||
grpc.credentials.createInsecure()); | ||
var user; | ||
if (argv._.length > 0) { | ||
user = argv._[0]; | ||
} else { | ||
user = 'world'; | ||
} | ||
client.sayHello({name: user}, function(err, response) { | ||
console.log('Greeting:', response.message); | ||
}); | ||
} | ||
|
||
main(); | ||
// These examples have been moved to https://github.com/grpc/grpc-node/tree/master/examples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1 @@ | ||
/* | ||
* | ||
* Copyright 2015 gRPC authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
var PROTO_PATH = __dirname + '/../../protos/helloworld.proto'; | ||
|
||
var grpc = require('@grpc/grpc-js'); | ||
var protoLoader = require('@grpc/proto-loader'); | ||
var packageDefinition = protoLoader.loadSync( | ||
PROTO_PATH, | ||
{keepCase: true, | ||
longs: String, | ||
enums: String, | ||
defaults: true, | ||
oneofs: true | ||
}); | ||
var hello_proto = grpc.loadPackageDefinition(packageDefinition).helloworld; | ||
|
||
/** | ||
* Implements the SayHello RPC method. | ||
*/ | ||
function sayHello(call, callback) { | ||
callback(null, {message: 'Hello ' + call.request.name}); | ||
} | ||
|
||
/** | ||
* Starts an RPC server that receives requests for the Greeter service at the | ||
* sample server port | ||
*/ | ||
function main() { | ||
var server = new grpc.Server(); | ||
server.addService(hello_proto.Greeter.service, {sayHello: sayHello}); | ||
server.bindAsync('0.0.0.0:50051', grpc.ServerCredentials.createInsecure(), () => { | ||
server.start(); | ||
}); | ||
} | ||
|
||
main(); | ||
// These examples have been moved to https://github.com/grpc/grpc-node/tree/master/examples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1 @@ | ||
# gRPC Basics: Node.js sample code | ||
|
||
The files in this folder are the samples used in [gRPC Basics: Node.js][], a detailed tutorial for using gRPC in Node.js. | ||
|
||
[gRPC Basics: Node.js]:https://grpc.io/docs/languages/node/basics | ||
These examples have been moved to [the grpc/grpc-node repository](https://github.com/grpc/grpc-node/tree/master/examples). |
Oops, something went wrong.