employee-microservice-node
Example Node.js CRUD microservice for an Employee entity with unit tests, mocking, code style checking and good test coverage. The microservice exposes REST APIs which are documented using Swagger.
Getting Started
Requirements:
Checkout and run the code
git clone https://github.com/omerio/employee-microservice-node.git
cd employee-microservice-node
npm install
npm start
Once the server is started you can access the following URLs:
- Server: http://localhost:8000/
- Swagger API documentation: http://localhost:8000/docs
Libraries
The following libraries are used in this project:
- Web Server Framework: hapi with swagger and good plugins. Boom for HTTP errors. Request for making HTTP requests
- Logging: winston
- Testing: mocha with chai for BDD and sinon for mocking
- Code Coverage: nyc
- Code Style: eslint
- Deployment: Docker
Available build scripts
The available scripts are in the package.json
file:
npm start
- start the applicationnpm run dev
- start the application in development mode, e.g. application reloads each time a change is made.npm test
- run the unit tests, the results are printed to the screennpm run test-ci
- run the unit tests, the results saved to a file to use in a Continous Integration toolnpm run test-debug
- run the tests enabling debug modenpm run coverage
- run the code coveragenpm run debug
- run the app in debug modenpm run lint
- run linting of the application code
Unit Tests and Coverage
To run the unit tests
npm test
The test results are printed to the screen. To produce the test results in junit format use the npm run test-ci
script
To generate the code coverage reports:
npm run coverage
The coverage reports are available in HTML format in employee-microservice-node/coverage/index.html
CI-CD
This repository uses CircleCI for continuous integration and deployment. Circle CI configuration is in the circle.yml
file
Code coverage results are uploaded to CodeCov.
Docker
This microservice can be built as a docker container. See the Dockerfile
To build a docker image:
docker build -t omerio/employee-microservice-node .
To run the docker image:
docker run -p 8000:8000 omerio/employee-microservice-node
Publish the image to Docker Hub, using your Docker Hub login details:
docker login
docker push omerio/employee-microservice-node
TODO
- Continuous deployment using CircleCI
- Add authentication
- Add JSDocs support