The ESNhapi is an API written in Node.JS that tries to centralize the content from all the network. With it, we try to provide a one stop place for fetching any kind of information.
ESNhapi is built on the API framework hapi.js, written in Javascript. To deploy and develop, there is a Docker configuration that creates a container with the API.
Development is done through Docker container. The development container syncs the code between the host folder and the container and reloads at any event of change of the code. Using containers allows to setup a development system, including databases and other options just with a command and 0 configuration.
-
Install docker
1.1 MacOS/Windows:
- Install Docker Toolbox: https://www.docker.com/products/docker-toolbox
- Install Docker Native
- Mac OS: https://download.docker.com/mac/beta/Docker.dmg
- Windows: https://download.docker.com/win/beta/InstallDocker.msi (with Hyper-V enabled machines only. Otherwise install Docker Toolbox for Windows)
1.2 Linux:
- Install docker-engine: https://docs.docker.com/engine/installation/
- Install docker-compose: https://docs.docker.com/compose/install/
-
Install npm packages for development:
npm install
-
Build the container:
npm run build
- Run the API and mongoDB containers:
npm start
- Run the tests and coverage:
npm test
You can find the real commands called in docker-compose inside the package.json
file.
If you want to run the containers as daemons (in background), add a -d
as a parameter to docker-compose
.
By default it will be run as a command and logs and changes will be printed in the console.
- http://localhost:3000: API port
- http://localhost:3000/documentation: Swagger API documentation endpoint
- http://localhost:5858: Node.JS debug port
- http://localhost:27017: MongoDB port
- http://localhost:5859: Node.JS debug port in test container
In order to run in local configurations, add mongo 127.0.0.1
in the hosts file of your computer
- Remote Debug configuration: Start a remote debugging connecting to
localhost:5858
- Run Local configuration: Start index.js in debug mode
Install node-inspector with sudo npm install -g node-inspector
and connect to it using
node-debug --web-host=127.0.0.1 --cli app/index.js
.
Note: this still needs to be tested!
Tests ar ran using mocha library as a test driver and istanbul as a coverage measurer.
Coverage outputs are saved in the coverage folders. Also they are saved as artifacts in GitlabCI.
npm test
- Run Tests local configuration: Start mocha from the command line
node_modules/.bin/_mocha --recursive
CI is done through Gitlab CI and steps are defined in .gitlab-ci.yml file.
There are 4 steps:
- Testing: Tests and code coverage are run against the code
- Building: The docker image is built and saved in the Gitlab Registry
- Deploying: The docker image is updated in the server using rancher-compose
- CleanUp: The update is finished or reverted back depending on the result of the previous Job.
We do Testing before Building, because the real building ('npm install') takes nothing. Building is building the docker image itself.