chapter two

2 Creating your first microservice

 

This chapter covers:

  • Our philosophy of development
  • Establishing your single-service development environment
  • Building a microservice for video streaming
  • Setup for production and development
  • Using Node.js to run our microservice

We are aiming to assemble a microservices-based application that consists of multiple microservices. But before we can build multiple microservices we must first learn how to build one microservice! We have to start somewhere and in this chapter we’ll create our first microservice. It will be simple microservice and do very little, but it will illustrate the process so that you can understand it and repeat it.

This first microservice will be a simple HTTP server that can deliver streaming video to a user watching in a web browser. This is the first step on our road to building FlixTube: our video streaming application. Video streaming might sound very difficult! But the simple code we are examining at this stage should not present much difficulty.

In this book, our microservices are programmed with JavaScript and run on Node.js. It’s important to note though that we could use any tech stack for our microservices. Building applications with microservices gives us a lot of freedom in the tech stack we use.

2.1   New tools

2.2   Getting the code

2.3   Why Node.js?

2.4   Our philosophy of development

2.5   Establishing our single-service development environment

2.5.1   Installing git

2.5.2   Cloning the code repo

2.5.3   Get Visual Studio Code

2.5.4   Installing Node.js

2.6   Building a HTTP server for video streaming

2.6.1   Creating a Node.js project

2.6.2   Installing Express

2.6.3   The Express boilerplate

2.6.4   Running our simple web server

2.6.5   Adding streaming video

2.6.6   Microservice configuration

2.6.7   Set up for production

2.6.8   Live reload for fast iteration

2.6.9   Running the finished code from this chapter

2.7   Node.js review

2.8   Where to go for more information

2.9   Summary