Use test-driven development to build a Node.js application
Create a world class currency conversion microservice using TDD in Node.js
This code pattern shows you how to create a world class currency conversion microservice that was built by using test-driven development (TDD) in Node.js. This code pattern is a microservice that is a part of the Bee Travels project.
This code pattern shows you how to create a world class currency conversion microservice using test-driven development (TDD) in Node.js. This code pattern is a microservice that is a part of the Bee Travels project.
Test-driven development is a style of programming that closely intertwines coding, testing, and designing. So, when designing the functionality of your application, you first write unit tests and then implement the code afterwards.
You need to understand test-driven development to follow the steps in this patterns.
- Read 5 steps of test-driven development for an introduction to test-driven development.
You also need to have the following installed on your local machine:
After completing this code pattern, you will understand how to:
- Design and create a Node.js microservice with a REST interface that has a swagger test harness where you can manually inspect, discover and run the various API endpoint.
- Use and run this simple microservice.
- Use the code base as a reference architecture and toolchain to create your own Node.js microservices.
- Deploy and run this microservice on Kubernetes.
This flow is for the runtime of the currency conversion microservice.
- Consumer calls the microservice over the Internet using an http/s request.
- The ExpressJS web server accepts the REST request (for example, GET /convertCurrency/ZAR/USD/600.66).
- Code routing in Express passes the request to a service module which in turn calls the European Currency Exchange API.
- An exchange rate for ZAR is retrieved and stored. The value of 600.66 South African Rands (ZAR) is converted to US Dollars(USD).
- The ExpressJS web server sends a response to the calling consumer with the dollar amount (in this case, $40.59 ).
- Clone the repo by running
git clone TDD-NodeJS-Containers.
- Ensure Node.js 10.16.1 or later is installed by running node -v.
- Install packages with NPM by running
- Start the app by running
- Browse the API from your browser