npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

grpcity

v2.1.5

Published

A powerful and complete gRPC framework for Node.js

Downloads

67

Readme

gRPCity build-status npm license

English | 简体中文

Introduction

gRPCity is a gRPC microservices library running on Node.js. It combines proto-loader and grpc-js to offer an exceptionally easy way to load proto files. It simplifies many complex technical concepts, allowing clients and servers to be implemented with just a few functions. Additionally, it provides numerous advanced features to meet the needs of most development scenarios.

The name is derived from "gRPC + City = gRPCity", symbolizing the author's hope that this library can support the development of business cities. Taking a technological perspective as the foundation, it enables everyone to focus on business and better support delivery.

Here is the feature:

  • API: Communication protocol is based on gRPC and defined through Protobuf.
  • Protobuf: Supports only dynamic load, simplifying the loading process of protobuf files.
  • Client: Configured once, callable anytime, anywhere, and supports multi-server invocation.
  • Server: Simplifies the initialization process with a three-step start, supporting multi-server deployment.
  • Credentials: Complete support for certificate loading on both the client and server.
  • No-Route: No routing, RPC is inherently bound to methods.
  • Middleware: Both client and server support middleware.
  • Metadata: Standardizes the transmission and retrieval of metadata.
  • Reflection: Built-in gRPC Reflection API in server.
  • Error: Provides dedicated Error objects to ensure targeted handling of exceptions after catching.
  • Promise: Supports promisify internally in RPC methods while also preserving callbackify.
  • Config: Supports protobuf load configurations and gRPC channel configurations.
  • Typescript: Implemented purely in TypeScript with comprehensive types.

...and a lot more.


View full documentation and examples on grpcity.js.org.

Quick Start

Install

npm i grpcity

Proto

First, create the greeter.proto file and write the following content in it:

syntax = "proto3";

package helloworld;

service Greeter {
  rpc SayGreet(Message) returns (Message) {}
}

message Message {
  string message = 1;
}

Loader

Next, create loader.js and write the following code in it:

import { ProtoLoader } from 'grpcity'
import path from 'node:path'

export default new ProtoLoader({
  location: path.join(__dirname, './'),
  files: ['greeter.proto']
})

Server

Then, create server.js and write the following code in it:

import loader from './loader.js'

class Greeter {
  async sayGreet(ctx) {
    const { message } = ctx.request
    return {
      message: `hello ${message || 'world'}`
    }
  }
}

const start = async (addr) => {
  await loader.init()

  const server = await loader.initServer()
  server.add('helloworld.Greeter', new Greeter())

  await server.listen(addr)
  console.log('gRPC Server is started: ', addr)
}

start('127.0.0.1:9099')

Client

Finally, create client.js and write the following code in it:

import loader from './loader.js'

const start = async (addr) => {
  await loader.init()

  const clients = await loader.initClients({
    services: {
      'helloworld.Greeter': addr
    }
  })

  const client = clients.get('helloworld.Greeter')
  const result = await client.sayGreet({ message: 'greeter' })
  console.log('sayGreet', result.response)
}

start('127.0.0.1:9099')

Once the programming work is completed, you can start it in the terminal by running:

node ./server.js
node ./client.js

View full documentation and examples on grpcity.js.org.

License

Released under the MIT License.