๐Ÿ“ฆ bryopsida / node-grpc-starter

A bare bones starter template for a node gRPC micro service

โ˜… 0 stars โ‘‚ 0 forks ๐Ÿ‘ 0 watching
grpcnodejsstarter-template
๐Ÿ“ฅ Clone https://github.com/bryopsida/node-grpc-starter.git
HTTPS git clone https://github.com/bryopsida/node-grpc-starter.git
SSH git clone git@github.com:bryopsida/node-grpc-starter.git
CLI gh repo clone bryopsida/node-grpc-starter
renovate[bot] renovate[bot] Update dependency pino to v10.2.1 (#384) 39cf240 2 days ago ๐Ÿ“ History
๐Ÿ“‚ main View all commits โ†’
๐Ÿ“ .devcontainer
๐Ÿ“ .github
๐Ÿ“ e2e
๐Ÿ“ services
๐Ÿ“ tools
๐Ÿ“„ .dockerignore
๐Ÿ“„ .gitignore
๐Ÿ“„ Dockerfile
๐Ÿ“„ jsdoc.json
๐Ÿ“„ main.js
๐Ÿ“„ main.spec.js
๐Ÿ“„ package-lock.json
๐Ÿ“„ package.json
๐Ÿ“„ README.md
๐Ÿ“„ renovate.json
๐Ÿ“„ server.js
๐Ÿ“„ server.proto
๐Ÿ“„ server.spec.js
๐Ÿ“„ README.md

node-grpc-starter

What is this?

A bare bones Node.JS gRPC starter template. It does not use typescript, it does not use any additional frameworks.

It provides boilerplate to start a gRPC microservice using an example echo service .proto file and dynamic bindings.

Dependencies

  • @grpc/grpc-js (core gRPC server)
  • @grpc/proto-loader (.proto parser for dynamic bindings)
  • @grpc/reflection (provide reflection calls for method discovery in clients like Postman)
  • grpc-health-check (provide health endpoints)
  • pino (logger)
  • dotenv (configuration)

Dev. Dependencies

  • nodemon (hot reloading on change)
  • standard (opinionated code linting)
  • node-forge (boostraps PKI for mTLS E2E testing in CI)
  • testcontainers (verify container builds and runs)
  • jsdoc (create html documentation folder from code comments)
node --test is used for testing instead of bringing in a library/framework.

Scripts

Scripts available in package.json

  • build:image builds a docker image
  • build:docs builds the docs folder using jsdoc
  • build:context creates a folder showing the files sent to the docker build context under the context folder
  • lint runs standard lint checks
  • lint:fix fixes all auto correctable lint failures
  • start runs the server
  • start:dev runs the server using nodemon and reloads on change
  • test runs tests

Workflows

A github workflow is included that

  • Runs unit tests and lint checks
  • Runs npm audit checks
  • Builds multi-platform docker image
  • Scans image using trivy and uploads results to GitHub

Environment Variables

NameDescriptionDefault
SERVERPORTBind port of the server3000
SERVERCACERTString value of the CA in PEM format
SERVERKEYPAIRSJSON array, each object containing a key and cert property
SERVERVALIDATECLIENTCERTBoolean toggling whether or not the server will validate the client certificate, when set to true this enables mTLSfalse
SERVERSUPRESSINSECUREWARNINGWhen running without TLS a warning is logged, setting this to true disables that log messagefalse
DOTENVFILEPATHSComma seperated list of paths to .env files, if not provided .env is used, encrypted files should have a .vault ending extension
DOTENVDEBUGWhen enabled debug messages from dotenv are loggedfalse
DOTENVVAULTKEYPATHWhen set, this path is used to load a key for decrypting .vault dotenv files, when set has priority over DOTENVVAULTKEY
DOTENVVAULTKEYWhen set, this is used to decrypt .vault dotenv files
DOTENVOVERRIDEWhen set to true, values specified in .env files will override values already defined in the destinationfalse

Automated Dependency Updates

A renovate configuration is provided to keep dependencies up to date and auto merge if tests pass.