This guide outlines how to deploy and configure the API via the commandline. For this setup, we used DigitalOcean droplets to create a simple VPS for hosting the API.
Note: This assumes that you already have a working database with the correct structure. For details, see the API Database Setup.
-
Clone the Repository
Start by cloning the entire repository onto your server:git clone <repository_url>
-
Install Node.js
If Node.js is not already installed on your server, you need to install it first. Use the following commands to install Node.js and npm (Node.js package manager) on Ubuntu-based systems:sudo apt update sudo apt install -y nodejs npm
You can check if Node.js and npm are installed correctly by running:
node -v npm -v
-
Install Dependencies
Navigate to the project directory and install all necessary dependencies using npm:cd <project_directory> npm install
-
Create a
.env
File
If you previously created a.env
file before cloning the project and it was added to.gitignore
, you will need to create it again.To create the .env file follow the instructions in Create the
.env
file -
Start the API
Run the following command to start the server:node app.js
The API should now be accessible on the configured IP and port. For a list of endpoints, refer to the API Endpoints documentation.
To ensure the API remains active even after you close the console, you can configure it to run as a systemd service.
-
Create a Systemd Service File
Add a systemd service file at/etc/systemd/system/API.service
with the following content:[Unit] Description=Node.js API Service After=network.target [Service] Group=www-data WorkingDirectory=/var/www/JIC-P.O.S/API ExecStart=/usr/bin/node /var/www/JIC-P.O.S/API/app.js Restart=always [Install] WantedBy=multi-user.target
Note: Update the file paths (
/var/www/JIC-P.O.S/API
) to match the actual location of your API files. It's recommended to place your application in/var/www
(create this directory if it does not exist). -
Enable and Start the Service
Use the following commands to enable and start the service:sudo systemctl enable API.service sudo systemctl start API.service
-
Verify the Service
Check the status of the service to ensure it is running:sudo systemctl status API.service
-
Restart the Service
To restart the API service after making changes:sudo systemctl restart API.service
-
Stop the Service
To stop the API service:sudo systemctl stop API.service
-
View Logs
To view logs generated by the service:journalctl -u API.service
With these steps completed, your API should be deployed and running continuously on the server.