Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/denpalrius/grpc-node-planets

A Node.js gRPC service for managing planets using TypeScript and Protocol Buffers, including both server and client implementations.
https://github.com/denpalrius/grpc-node-planets

grpc nodejs protobuf protocol-buffers rpc typescript

Last synced: about 1 month ago
JSON representation

A Node.js gRPC service for managing planets using TypeScript and Protocol Buffers, including both server and client implementations.

Awesome Lists containing this project

README

        

# gRPC Node.js Planets

This project demonstrates the use of gRPC with Node.js and TypeScript to create a simple planets service.

## Project Structure

The project consists of a gRPC server and client implementation for managing planet data.

- `src/server`: Contains the server implementation
- `src/client`: Contains the client implementation
- `proto`: Contains the Protocol Buffers definition and autogenerated schema

## Installation

1. Clone the repository
2. Install dependencies:

```bash
npm install
```

## Usage

### Generate Protocol Buffers

Before running the server or client, generate the necessary Protocol Buffers files:

```bash
npm run proto:gen
```

### Running with TypeScript

You can run the server and client directly using TypeScript:

Start the server:
```bash
npm run server
```

Run the client:
```bash
npm run client
```

### Running with JavaScript

To run the transpiled JavaScript version:

1. Build the project:
```bash
npm run build
```

2. Start the server:
```bash
npm run server:js
```

3. Run the client:
```bash
npm run client:js
```

The server will start on `localhost:3000`.

The client will perform the following operations:
1. Fetch all planets
2. Get the first planet
3. Create a new random exoplanet
4. Fetch the updated list of planets

## Scripts

- `npm run proto:gen`: Generate Protocol Buffers files
- `npm run clean`: Remove the dist directory
- `npm run build`: Clean and compile TypeScript
- `npm run server`: Run the TypeScript server directly
- `npm run client`: Run the TypeScript client
- `npm run server:js`: Run the compiled JavaScript server
- `npm run client:js`: Run the compiled JavaScript client

## Resources

- [gRPC Documentation](https://grpc.io/docs/)
- [Protocol Buffers Documentation](https://developers.google.com/protocol-buffers/docs/overview)
- [Node.js gRPC Tutorial](https://grpc.io/docs/languages/node/quickstart/)
- [Implementing a gRPC client and server in Typescript with Node (Youtube)](https://www.youtube.com/watch?v=H0c4Wjl4kRQ&ab_channel=JustinBrooks)