The purpose of this file is to document the storefront backend project. It contains the following informations:
- How to install and configure the project
- How to setup and configure the database
- How run tests and lunch application
To install the project, you must follow these steps:
- Configure the environment
- Run docker-compose to lunch the database system
- Install project dependencies (node dependencies)
- Run the tests and lunch the application
To configure the application and setup the database you need to configure the environment.
It consists of adding a .env inside the root folder of the application.
By default there is a .env.example file in the project directory.
It contains a sample environment configuration for the project.
You can copy it and rename it to .env and provide your configuration values.
The following table lists the important variables that must be present in the env file.
Environment variable | Purpose | Type of content |
---|---|---|
ENV | Configure the environment the application will be running in | Possible values are prod and test |
TOKEN_SECRET | The secret key used to sign JWT tokens | Any long string |
SALT | Addition for password encryption | Any long string |
ROUNDS | Encryption strengthning rounds | An integer value (Example: 10) |
POSTGRES_USER | PostgreSQL database user name | String value |
POSTGRES_PASSWORD | PostgreSQL database password | String value |
POSTGRES_DB | PostgreSQL production database name | String value |
POSTGRES_DB_TEST | PostgreSQL test database name | String value |
This task assumes you have docker and docker-compose installed. If not follow these links to install docker and docker-compose. Once you have docker and docked compose installed, you can start the database server with the following command:
docker-compose up -d
Depending on your operating system, you can have to add sudo to run the command with super user privileges.
To install project dependencies you can run the following commands depending on your package manager.
npm install
or
yarn
To run the test suites, run the following command:
npm run test
Don't mind creating the test database by hand. The test script can do the following if the .env file is well configured:
- Create the test database
- Run all tests
- Cleanup the test database if everything went on succesfully.
To succesfully lunch the application, you need edit the .env file and change the ENV key back to prod. You can now lunch the application by running:
npm run start
If everything went on succesfully, the application will start on port 3000.
You can now access it typing: http://localhost:3000
Element | Value |
---|---|
Application port | 3000 |
Application URL | http://0.0.0.0:3000 |
PostgreSQL database host | 0.0.0.0 |
PostgreSQL database PORT | 5432 |