KeithMoc / moleculer-typescript-template

This is a Moleculer-based microservices project

Home Page:https://moleculer-typescript.fly.dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Welcome to moleculer-typescript-template 👋

Version Prerequisite Twitter: jellydn

My Moleculer-based microservices project

Moleculer - Progressive microservices framework for Node.js

Prerequisites

  • node >= 16.20.x

Init new project

npx degit jellydn/moleculer-typescript-template [PROJECT-NAME]

Features

  • ⚡️ Progressive microservices framework for Node.js. Moleculer with Typescript template
  • 📦 hygen - The scalable code generator that saves you time.
  • 🦾 pino - super fast, all natural json logger
  • 🔥 swagger-jsdoc - Generates swagger/openapi specification based on jsDoc comments and YAML files.

Install

yarn install

Usage

# Copy env file
cp .env.example .env
yarn dev

After starting, open the http://localhost:3000/ URL in your browser. On the welcome page you can test the generated services via API Gateway and check the nodes & services. https://gyazo.com/c8a8c8b05319504d36922458d9807db2.gif

yarn cli --ns api

https://gyazo.com/235f710ab3fd906f80768261e793eb13

In the terminal, try the following commands:

  • nodes - List all connected nodes.
  • actions - List all registered service actions.
  • call greeter.hello - Call the greeter.hello action.
  • call greeter.welcome --username dunghd - Call the greeter.welcome action with the username parameter.

https://gyazo.com/3aca1c4e1992ad1c10da8060d7e21a6c.gif

Code generator

Add new service to your project with below command

yarn generate:service [service-name]

API Documentation

This template also reads your JSDoc-annotated source code and generates an OpenAPI (Swagger) specification.

Open the http://localhost:3000/docs URL in your browser, you will see the Swagger UI as

https://gyazo.com/a4fe2413414c94dde636a531eee1a4a0.gif

Run tests

yarn test

Deployment

This template comes with two GitHub Actions that handle automatically deploying your app to production and staging environments.

Prior to your first deployment, you'll need to do a few things:

  • Install Fly

  • Sign up and log in to Fly

    fly auth signup
  • Create two apps on Fly, one for staging and one for production:

    fly create moleculer-typescript
    fly create moleculer-typescript-staging
  • Create a new GitHub Repository

  • Add a FLY_API_TOKEN to your GitHub repo. To do this, go to your user settings on Fly and create a new token, then add it to your repo secrets with the name FLY_API_TOKEN.

Now that every is set up you can commit and push your changes to your repo. Every commit to your main branch will trigger a deployment to your production environment, and every commit to your dev branch will trigger a deployment to your staging environment.

GitHub Actions

We use GitHub Actions for continuous integration and deployment. Anything that gets into the main branch will be deployed to production after running tests/build/etc. Anything in the dev branch will be deployed to staging.

Useful links

NPM scripts

  • yarn dev: Start development mode (load all services locally with hot-reload & watch)
  • yarn start: Start production mode (set SERVICES env variable to load certain services)
  • yarn cli: Start a CLI and connect to production. Don't forget to set production namespace with --ns argument in script
  • yarn ci: Run continuous test mode with watching
  • yarn test: Run tests & generate coverage report
  • yarn dc:up: Start the stack with Docker Compose
  • yarn dc:down: Stop the stack with Docker Compose

Author

👤 Dung Huynh

Show your support

Stargazers repo roster for @jellydn/moleculer-typescript-template

Give a ⭐️ if this project helped you!

About

This is a Moleculer-based microservices project

https://moleculer-typescript.fly.dev/

License:MIT License


Languages

Language:TypeScript 48.2%Language:HTML 43.6%Language:EJS 7.1%Language:Dockerfile 1.0%Language:Shell 0.1%