This repository contains the backend API built for my (Professional) Master thesis where I developed an application for storing information about different plant species, subspecies, useful parts and etc.
This API is build on top of NodeJs and is build as a REST API containing GET, POST, PATCH and DELETE methods for the selected resources. This backend also has an implemantaion of authentication endpoints and functionalities like password reset as well as authorization so POST, PATCH and DELETE methods can only be accessed by users with the role SUPER_ADMIN.
- Node.Js
- Express.js
- Firebase
- Objection.js
- Multer
- MySQL
A brief summary on how to deploy the backend for the plant-species project
- Nginx/Apache
- PM2
- Firebase Project
- Transfer the directory of the backend to the server folder
/var/www
andcd
into it - Copy paste the
.env.example
file to.env
and populate all parameters (some parameters are described below)- FIREBASE_PROJECT_ID:
- Open the Firebase project
- Go to Settings
- General
- Copy the Project ID and paste it into the
.env
file
- FIREBASE_KEY:
- Open the Firebase project
- Go to Settings
- Service accounts
- Choose Node.js and click Generate new private key
- Rename the file to
firebase.json
and transfer it to the root folder of the project - Set the value of the
.env
parameter to the file namefirebase.json
- FIREBASE_BUCKET:
- Open the Firebase project
- Go to Storage and enable the service
- Take the value after the
gs://
prefix of the url and set it as the value of the.env
parameter
- FRONTEND_DOMAIN:
- Example: for the URL: https://biljne-vrste.huxian.me/ the value of the
.env
parameter has to be set to biljne-vrste.huxian.me
- Example: for the URL: https://biljne-vrste.huxian.me/ the value of the
- BACKEND_DOMAIN:
- Example: for the URL: https://biljne-vrste-api.huxian.me/ the value of the
.env
parameter has to be set to biljne-vrste-api
- Example: for the URL: https://biljne-vrste-api.huxian.me/ the value of the
- NODE_ENV:
- For a production environment set it to
production
- For a production environment set it to
- JWT_SECRET:
- Set the value of the
.env
parameter to a random generated string Example
- Set the value of the
- FIREBASE_PROJECT_ID:
- Run the command
npm install
to install all project dependencies - Run the command
npx knex migrate:latest
to create the database schema and tables - Run the command
npx knex seed:run
to populate tables with values from theseeds
folder - Run the command
pm2 start app.js --name=plant-species-backend
- Go into the
nginx/apache
config and setup areverse proxy
to the application you ran withpm2
manager (Example of theconfig
file for nginx below)server { server_name biljne-vrste-api.huxian.me; location / { proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header Host $http_host; proxy_pass http://localhost:3000; } }
- Run the following script to create the first user in the application
./scripts/CreateSuperAdmin.js create-super-admin create-super-user [email protected] --password=testpassword
- The backend for the project should be set now