Skip to content

imanolpg/energy_pilot_backend

Repository files navigation

EnergyPilot Backend

Backend API for EnergyPilot mobile app. Includes 🔦 eslint for linting/code formatting, 🔛 nodemon for automatic server restarting, and ✅ Jest for testing.

It is also 🐳 dockerized with with the API and a 🐬 MySQL database.

test workflow GitHub top language

GitHub last commit GitHub issues GitHub closed issues

Getting Started

Install dependencies

npm install

Environment variables

Env variables are loaded with nconf with a cascade aproach. Variables are loaded in the following order Command-line arguments ➡️ Environment variables ➡️ Argument variables ➡️ path/to/config.json. Aditionally there is a section for default values if one variable is not present. If one variable has been loaded previously and it appears in any next stage it will be overwritten with the last values.

In development, a .env🤫 file has been included in the project directory with the following variables set.

DB_HOST
DB_USER
DB_PASSWORD
DB_SCHEMA
DB_PORT
DB_ROOT_PASSWORD

JWT_SECRET_TOKEN

PUBLIC_SALT

SSL_KEY
SSL_CERT

Running in development

The project will be automatically compiled ans served whenever a file is modified. There is no need to manually build and start the server

npm run dev

Runs on localhost:8000

Running in production

npm run build && npm run start

Runs on localhost:8000

Running tests

npm test

Docker 🐳

This repository contains a dockerized version of the API, orchestrated with Docker Compose.

Prerequisites

Before running the application with Docker Compose, you must have the following tools installed on your machine:

Getting Started

To run the application with Docker Compose, simply run the following command in the root directory of the project:

docker-compose build --no-cache 
docker-compose up

This will build the application image and start the container. You can then access the application by navigating to https://localhost:8000. Ports 8000 and 3307 are exposed

Configuration

The application can be configured by modifying the docker-compose.yml file in the root directory of the project.

Dependencies and Volumes

This app requires a MySQL database and a MySQL image has been included from Docker Hub. Port 3307 has been exposed and acces to the MySQL server is allowed. The credentials can be configured in a .env file as explained before.

To make stored data in MySQL persistant, a volume has been created dbdata:/var/lib/mysql

About

Backend API for EnergyPilot app

Resources

Stars

Watchers

Forks