Book Image

TypeScript Microservices

Book Image

TypeScript Microservices

Overview of this book

In the last few years or so, microservices have achieved the rock star status and right now are one of the most tangible solutions in enterprises to make quick, effective, and scalable applications. The apparent rise of Typescript and long evolution from ES5 to ES6 has seen lots of big companies move to ES6 stack. If you want to learn how to leverage the power of microservices to build robust architecture using reactive programming and Typescript in Node.js, then this book is for you. Typescript Microservices is an end-to-end guide that shows you the implementation of microservices from scratch; right from starting the project to hardening and securing your services. We will begin with a brief introduction to microservices before learning to break your monolith applications into microservices. From here, you will learn reactive programming patterns and how to build APIs for microservices. The next set of topics will take you through the microservice architecture with TypeScript and communication between services. Further, you will learn to test and deploy your TypeScript microservices using the latest tools and implement continuous integration. Finally, you will learn to secure and harden your microservice. By the end of the book, you will be able to build production-ready, scalable, and maintainable microservices using Node.js and Typescript.
Table of Contents (17 chapters)
Title Page
Copyright and Credits
Packt Upsell
Contributors
Preface
Index

Writing your first Hello World microservice


Let's start by writing our first microservice. Based on the previous topics, we will construct our first microservice with best practices and the widely used node_modules. We will use:

CORS (https://www.npmjs.com/package/cors)

Adds CORS headers, so that cross applications can access it.

Routing Controllers (https://www.npmjs.com/package/routing-controllers)

Beautiful decorators provided in this module, which help us to write our API's and routes easily.

Winston (https://www.npmjs.com/package/winston)

Perfect logging module with many advanced features.

So, open up a Terminal and create one Node project with a default package.json. Follow these steps. The full source code for reference is available in the first-microservice folder in the extracted source:

  1. First of all, we will download the preceding dependencies and basic express dependencies. Enter the following command lines:
npm install body-parser config cookie-parser cors debug express reflect-metadata...