Giter Club home page Giter Club logo

moleculer-typescript-template's Introduction

Welcome to moleculer-typescript-template ๐Ÿ‘‹

Version Prerequisite Twitter: jellydn

My Moleculer-based microservices project

Moleculer - Progressive microservices framework for Node.js

IT Man - Automating API Client Generation with openapi-ts

Prerequisites

  • node >= 18.17.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.
  • โœจ moleculer-zod-validator - A validator for the Moleculer microservice framework to allow the use of Zod.
  • ๐Ÿ” asteasolutions/zod-to-openapi - A library that generates OpenAPI (Swagger) docs from Zod schemas.
  • ๐Ÿช„ hey-api/openapi-ts - Turn your OpenAPI specification into a beautiful TypeScript client.

Install

pnpm install

Usage

# Copy env file
cp .env.example .env
pnpm 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

pnpm 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

This project uses hygen to generate code templates, saving you time and ensuring consistency across your codebase.

Adding a New Service

To add a new service to your project, use the following command:

pnpm generate:service [service-name]

Adding a New Action to a Service

To add a new action to an existing service, use the following command:

pnpm generate:action [action-name] --service [service-name]

Generating CRUD Services

To generate a service with Create, Read, Update, and Delete (CRUD) operations, use the following command:

pnpm generate:crud [service-name]

API Documentation

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

Run the following command to generate the Swagger documentation:

pnpm generate:swagger

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

https://gyazo.com/a4fe2413414c94dde636a531eee1a4a0.gif

Run tests

pnpm 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

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

Pre-commit hooks

This template uses Pre-commit to run checks before you commit your code. This ensures that your code is formatted correctly and passes all tests before you push it to your repository.

pre-commit install

To run the checks manually, use the following command:

pre-commit run --all-files

Author

๐Ÿ‘ค Dung Huynh

Show your support

Star History Chart

Give a โญ๏ธ if this project helped you!

kofi paypal buymeacoffee

moleculer-typescript-template's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

moleculer-typescript-template's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Awaiting Schedule

These updates are awaiting their schedule. Click on a checkbox to get an update now.

  • chore(deps): lock file maintenance

Detected dependencies

docker-compose
docker-compose.yml
  • nats 2
  • traefik v3.0
dockerfile
Dockerfile
  • node 20.13.1-alpine
  • node 20.13.1-alpine
github-actions
.github/workflows/code_review.yml
  • actions/checkout v4
  • mongolyy/reviewdog-action-biome v1
  • actions/checkout v4
  • reviewdog/action-misspell v1
.github/workflows/deploy.yml
  • styfle/cancel-workflow-action 0.12.1
  • actions/checkout v4
  • actions/setup-node v4
  • styfle/cancel-workflow-action 0.12.1
  • actions/checkout v4
  • actions/setup-node v4
  • styfle/cancel-workflow-action 0.12.1
  • actions/checkout v4
  • actions/setup-node v4
  • styfle/cancel-workflow-action 0.12.1
  • actions/checkout v4
  • SebRollen/toml-action v1.2.0
  • docker/setup-buildx-action v3
  • actions/cache v4
  • docker/login-action v3
  • docker/build-push-action v5
  • styfle/cancel-workflow-action 0.12.1
  • actions/checkout v4
  • SebRollen/toml-action v1.2.0
.github/workflows/pre_commit.yml
  • actions/checkout v4
  • actions/setup-python v5
  • pre-commit/action v3.0.1
.github/workflows/pull_request.yml
  • actions/checkout v4
  • biomejs/setup-biome v2
.github/workflows/test.yml
  • actions/checkout v4
  • oven-sh/setup-bun v1
  • actions/checkout v4
  • oven-sh/setup-bun v1
npm
package.json
  • @asteasolutions/zod-to-openapi 7.0.0
  • dotenv 16.4.5
  • helmet 7.1.0
  • lodash.defaultsdeep 4.6.1
  • moleculer 0.14.33
  • moleculer-web 0.10.7
  • moleculer-zod-validator 3.3.1
  • nats 2.25.0
  • openapi-types 12.1.3
  • pino 9.0.0
  • swagger-jsdoc 6.2.8
  • yaml 2.4.2
  • zod 3.23.8
  • @biomejs/biome 1.7.3
  • @flydotio/dockerfile 0.5.7
  • @hey-api/openapi-ts 0.43.2
  • @types/express 4.17.21
  • @types/jest 29.5.12
  • @types/lodash 4.17.1
  • @types/node 20.12.11
  • @types/swagger-jsdoc 6.0.4
  • @types/ws 8.5.10
  • @vitest/ui 1.6.0
  • c8 9.1.0
  • cleye 1.3.2
  • express 4.19.2
  • graphql 16.8.1
  • graphql-ws 5.16.0
  • hygen 6.2.11
  • moleculer-connect 0.2.2
  • moleculer-io 2.2.0
  • npm-run-all2 6.1.2
  • pino-pretty 11.0.0
  • sort-package-json 2.10.0
  • tsup 8.0.2
  • tsx 4.10.0
  • typescript 5.4.5
  • vite 5.2.11
  • vitest 1.6.0
  • wait-on 7.2.0
  • ws 8.17.0
  • node >= 18.17.x
  • pnpm 9.1.0
nvm
.nvmrc

  • Check this box to trigger a request for Renovate to run again on this repository

Issue with command "yarn dev"

Describe the bug

I have executed the command "yarn dev" but encountered an error. Please help me fix it. Thank you very much

PS E:\MBW.Moleculer\demo\moleculer-demo> yarn dev
yarn run v1.22.19
$ tsup --watch --onSuccess 'node_modules/.bin/moleculer-runner --env --config dist/moleculer.config.js'
CACError: option --env.* <value> value is missing
at Command.checkOptionValue (E:\MBW.Moleculer\demo\moleculer-demo\node_modules\cac\dist\index.js:417:17)
at CAC.runMatchedCommand (E:\MBW.Moleculer\demo\moleculer-demo\node_modules\cac\dist\index.js:603:13)
at main (E:\MBW.Moleculer\demo\moleculer-demo\node_modules\tsup\dist\chunk-RCEDGIWE.js:223:13)
at Object. (E:\MBW.Moleculer\demo\moleculer-demo\node_modules\tsup\dist\cli-default.js:12:23)
at Module._compile (node:internal/modules/cjs/loader:1126:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
at Module.load (node:internal/modules/cjs/loader:1004:32)
at Function.Module._load (node:internal/modules/cjs/loader:839:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Reproduction

When run command "yarn dev"

System Info

yarn dev

Used Package Manager

yarn

Validations

  • Follow our Code of Conduct
  • Read the Contributing Guide.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • The provided reproduction is a minimal reproducible of the bug.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.