API and Database for the conection and the functioning of the trip management system portal developed in course TC3005B by group 501.
In order to run this Backend, the following steps are required:
The only option currently is to clone the repository locally from GitHub.
git clone https://github.com/101-Coconsulting/TC3005B.501-Backendgh repo clone 101-Coconsulting/TC3005B.501-BackendThe dependencies for this project are managed using the pnpm package manager, so it is recommended to use this. However, npm can also be used. The dependencies are automatically managed by pnpm in the package.json file, so they are installed automatically when issuing the install command.
pnpm installnpm installTo succesfully create the certificates to use the server with HTTPS you will need to follow the next steps:
Important
You have to download the .cnf file provided in SharePoint and place it in the /certs directory.
-
Access the
/certsdirectory.cd certs -
Run the next line of code in the terminal to ensure the
/certs/create_certs.shfile is executable:chmod +x create_certs.sh
-
Run this line of code to create the certificates:
./create_certs.sh
Now you should have 6 new files in the /certs directory and should be able to run the server using HTTPS.
Caution
After creating the certificates, when making a commit be sure not to be uploading the certificates to the repository.
For the database to be operational, some initial configuration is required.
In order to properly setup MariaDB, the following steps are required:
- Download
mariadb. - It is recommended that you secure your MariaDB installation.
- Start the
mariadbserver. - To setup the database with dummy data, run
pnpm dummy_dbornode database/config/dev_db.jsfrom the root of the repository. - To setup only the database, run
pnpm empty_dbornode database/config/init_db.jsfrom the root of the repository.
- Go to the /database/Scheme directory.
cd database/Scheme - Run the
mariadbclient in batch mode. WithDB_USERandDB_USER_PASSWORDbeing your createdmariadbuser and its password. i. Load database scheme /database/Scheme/Scheme.sql.sh mariadb -u DB_USER -p DB_USER_PASSWORD < Scheme.sqlii. Load database initial prepopulation /database/Scheme/Prepopulate.sql.sh mariadb -u DB_USER -p DB_USER_PASSWORD < Prepopulate.sqliii. Load database triggers /database/Scheme/Triggers.sql.sh mariadb -u DB_USER -p DB_USER_PASSWORD < Triggers.sqliv. Load database views /database/Scheme/Views.sql.sh mariadb -u DB_USER -p DB_USER_PASSWORD < Views.sqlv. Load database dummy data /database/Scheme/Dummy.sql.sh mariadb -u DB_USER -p DB_USER_PASSWORD < Dummy.sql
- Download
mongodbusing your preferred method or package manager. - Download
mongoshif you want to interact with the database directly (recommended). - Test that mongo was installed correctly by running the
mongodormongoshcommand.mongodwill usually return error codes since no connection is currently made to then database. - Verify that mongo is running using
systemctl status mongod - If the status appears as inactive, use the command
systemctl start mongod
Finally, it is crucial that a local .env file is created. Based off of the .env.example file provided, which includes all necessary environment variables to be set in order for the server to be able to connect to the mariadb database, as well as the required JSON Web Token(JWT) information required for verifying authorized requests and encryption.
- Go to the root directory of your local repository.
- Create your
.envfile based off of the.env.examplefile.cp .env.example .env
- Edit the newly created
.envfile, and edit the required variables based on your previousmariadbconfiguration andmongodbconfiguration:# Server Configuration PORT=3000 NODE_ENV=development # Database Configuration DB_HOST=localhost DB_PORT=27017 DB_NAME=travel_management # Change this DB_USER=username # Change this DB_PASSWORD=password # Change this # JWT Configuration JWT_SECRET=your_jwt_secret_key # Change this JWT_EXPIRES_IN=1d # API Keys (if needed) # API_KEY=your_api_key # Other Configuration # CORS_ORIGIN=http://localhost:3000 MONGO_URI=mongodb://localhost:27017
To run the Backend, ensure the mariadb and mongodb servers are running, and utilize whichever package manager you used for dependencies to run the project.
pnpm run devnpm run devAnd you're good to go! nodemon should start and you should be able to start sending requests to your specified PORT on localhost as well as a confirmation message of connection to the file database!