Skip to content

andersonRocha091/tracker_api

Repository files navigation

Tracker API

This project it's an backend API for fleet tracking. It was built in NodeJS 12.8, and it comes with Hapi.js, TDD and unit test, strategy pattern for multi-data source utilization, pm2 monitoring, and all infra-structure already dockerized. OBS: It could be used Sequelize, or another ORM which better suits for you, I did it by my own for performance issues.

Pre-requirements

  • Docker version 19.03 or above
  • Docker-machine version 0.16.0, or above
  • Docker-compose version 1.26.0, or above
  • Node version 12.8, or above - Node Donwload
  • NPM version 6.14.4, or above- Npm Donwload

Installing

Clone this project in your machine using the command below:

	git clone https://github.com/andersonRocha091/tracker_api.git

Go to the project folder at your terminal:

	cd tracker_api

if not already exists create a .env (Settings for local mysql running at container and API) file with the following params for your environment:

ROOT_PASSWORD=<your-desired-root-password> //root password for local mysql running at container
MYSQL_DATABASE=fleetwise_prd //default local mysql database created on build
PMA_HOST=mysql2 //host for phpmyadmin mysql admin (mysql container)
PMA_PORT=3306 //deafault mysql port
UPLOAD_LIMIT=300000000
NODE_ENV=<'prod|dev'> //environment app excution

Inside the aplication folder src/config, change the params:

in .env.dev
PORT=5000 //default port
MYSQL_HOST=localhost //running locally by default
MYSQL_USER=root //default local mysql instance running at container
PASSWORD=<'your-root-database-password'>
DATABASE=fleetwise_prd //default database

in .env.prod - (make sure you whitelisted all ips using 0.0.0.0/0 at your mysql host).

PORT=5000
MYSQL_HOST=<database-host-url>
MYSQL_USER=<your-database-username>
PASSWORD=<your-database-password>
DATABASE=<database-name>

Execution

After setting up the .env's files you can run the api in production or in development mode. In terminal, inside tracker_api start all containers:

docker-compose up -d --build

The app will run at NODE_ENV mode assigned at .env file. If you change it, you need to run the previous command again.

you would be able to access the aplication endpoints by accessing localhost:5000/route

OBS: There's also a phpmyadmin available for local mysql management by default set in localhost:81. (Feel free to use adminer, or anything else which better suit for you)

Endpoints

Speed rank by tracker

Events by tracker uid

Tracker information related

Testing

The API was built using TDD and it is almost fully covered by unit tests. In order to run the TDD tests, just use the following command:

npm run test

OBS: I recommend you run it locally because this comand start another api instace, and the container one will be using the same port in the enviroment you choose at .envs file. This can be solved by running the command locally and changing in .env.{prod|dev} port to another one different from the default 5000.

Author

  • Anderson Souza Rocha - Full-stack developer - Github

License

MIT License (MIT)


Author ❤ Anderson Souza Rocha

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published