
Moleculer start with typescript
Hi guys,
Today I’m going to write a project using typescript, also understand how to use routes for different services or endpoints.
When you use microservices you can do all services for apps and use rules to features or versions.
let’s start.
moleculer init project-typescript moleculer-typescript

to run develop you need to remove a transport option in moleculer.config.ts
transporter: "",//"MQTT",
now execute the command yarn dev

open your browser http://localhost:3000/

you have a service, we will erase these services and write our services.

now we have the file, from service to post
we will use the MongoDB to it install
yarn add moleculer-db moleculer-db-adapter-mongoose mongoose
For example, you need to create a model for our service
in a folder, models create posts.ts file
now we can use it in service.
note: that here you can use different database for your services
let’s use the REPL command line, to test our service

find using ID

to get all records we use post.list method

to use it with API we can insert routes

When use Rest the Moleculer create all routers used in rest API.
it’s Work !!
Repo:
https://github.com/devalexandre/moleculer-typescript-article
Telegram Group
https://t.me/moleculer_en
References:
https://moleculer.services/docs/0.14/moleculer-repl.html
https://moleculer.services/docs/0.14/modules.html#Databases-amp-stores