--- /dev/null
+# TS Greeter example
+
+The following is an example on how to run the TS grpc server. Make sure that you have `Typescript` installed
+
+you would need to run `npm run build` or simply use `npm install && tsc`
+
+## How to run Server:
+
+- `npm run server`
+
+## How to run Client:
+
+- `npm run client 3000`
\ No newline at end of file
"name": "flatbuffers-js-grpc",
"version": "1.0.0",
"author": "mustii@mmk.one",
+ "scripts": {
+ "build": "npm install && tsc",
+ "client": "node dist/client.js",
+ "server": "node dist/server.js"
+ },
"dependencies": {
"flatbuffers": "^1.12.0",
"grpc": "^1.24.3"
import { GreeterClient } from './greeter_grpc';
import { flatbuffers } from 'flatbuffers';
-async function main(PORT: Number) {
+async function main(PORT: Number, name: String) {
const _server = new GreeterClient(`localhost:${PORT}`, grpc.credentials.createInsecure());
const builder = new flatbuffers.Builder();
- const offset = builder.createString('mustii');
+ const offset = builder.createString(name);
const root = HelloRequest.createHelloRequest(builder, offset);
builder.finish(root);
const buffer = HelloRequest.getRootAsHelloRequest(new flatbuffers.ByteBuffer(builder.asUint8Array()));
data.on('data', (data) => {
console.log(data.message());
});
- data.on('end', (data) => {
- console.log('end');
- });
}
-var PORT = Number(process.argv.slice(2));
+const args = process.argv.slice(2)
+const PORT = Number(args[0]);
+const name = String(args[1] ?? "flatbuffers");
+
if (PORT) {
- main(PORT);
+ main(PORT, name);
} else {
throw new Error("Requires a valid port number.")
}
\ No newline at end of file