Skip to content

Juansecu/Votatoon-API

Repository files navigation

Votatoon API

Description

Open-source web API for Votatoon client.

Requirements

Environment variables

In order for setting up the Votatoon API, you will need to set up the following environment variables:

  • DATABASE_HOST - The host where the database server is running
  • DATABASE_NAME - The name of the database to connect to
  • DATABASE_PASSWORD - The password of the user who owns the database
  • DATABASE_PORT - The port where the database server is running
  • DATABASE_SYNCHRONIZE - Whether the database should be synchronized with the entities. Set to 1 for development and first set up of the application, and 0 for production
  • DATABASE_USERNAME - The name of the user who owns the database
  • INIT_VECTOR - The initial vector that is used to encrypt/decrypt IP addresses from the clients
  • SECURITY_KEY - The security key that is used to encrypt/decrypt IP addresses from the clients

IMPORTANT:

  • You can generate values for INIT_VECTOR and SECURITY_KEY environment variables by using online tools like All Keys Generator.
  • Both INIT_VECTOR and SECURITY_KEY must be 512-bit, must have 32 characters and cannot be hex (unless they're 256-bit).
  • Avoid using the same value for both INIT_VECTOR and SECURITY_KEY environment variables.
  • You can set the values of the environment variables in your terminal by using the export command.
  • Avoid using characters like ", ', $ and ! in the values of the environment variables.
  • Once you set the values of the environment variables, you will need to create another session in your terminal in order to allow the application to access the new environment variables.
  • You must set up the environment variables by setting them for your Operating System internal use.

Setting environment variables in your Operating System

  • Windows:

    1. Open Settings > System > About > Advanced system settings > Environment Variables.
    2. Now, you can decide whether defining environment variables for specific users or for the entire Operating System. My personal suggestion is to define them for specific users.
    3. Click New... button.
    4. Type variable name and value.

    You have to follow steps 3 and 4 per environment variable.

  • Linux:

    Before starting, you must know that you can use the export command to set environment variables on Linux, but they may not be available after you leave your current session, so maybe you will want to set the environment variables using .(bash/zsh)_profile file.

    1. In order to set the environment variables, you have to use the export command followed by the key-value pair (like .env files). F.E To set DATABASE_NAME environment variable, you must use the command export DATABASE_NAME={{Database name}} (without {{}}).
    2. If you used .(bash/zsh)_profile to set the environment variables, you have to use the command source path/to/profile/file/.(bash/zsh)_profile, so your current session in the terminal will be updated with the new set environment variables.

    For more information about setting environment variables on Linux, you can check out this tutorial.

Available port

This application needs port 3000 by default for running on, but if you want to use a different port, you can set it by setting the environment variable PORT.

Note that this behavior allows you to deploy your own instance using a VPS/PaaS like Heroku or Digital Ocean.

API documentation

Once you have running the application, you can go to http://<address of host where you're running the application>:<port where you're running the application>/api to see the API documentation, so you can understand how this application works when it receives any request.

Installation

# development
$ npm install

# production mode
$ npm install --prod

Running the app

# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod

Test

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov

License

This project is MIT licensed.