Skip to content

Commit

Permalink
Replace Node example files with references to the new location
Browse files Browse the repository at this point in the history
  • Loading branch information
murgatroid99 committed Jun 22, 2023
1 parent 32a46a9 commit 0381846
Show file tree
Hide file tree
Showing 22 changed files with 22 additions and 4,117 deletions.
51 changes: 1 addition & 50 deletions examples/node/README.md
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).
2 changes: 1 addition & 1 deletion examples/node/dynamic_codegen/README.md
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).
58 changes: 1 addition & 57 deletions examples/node/dynamic_codegen/greeter_client.js
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
53 changes: 1 addition & 52 deletions examples/node/dynamic_codegen/greeter_server.js
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
6 changes: 1 addition & 5 deletions examples/node/dynamic_codegen/route_guide/README.md
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).

0 comments on commit 0381846

Please sign in to comment.