In this section, you will execute commands to connect to the ors-ec2 server, then install the environment and deploy the Node.js backend application.
Note: The commands must be executed sequentially. Ensure you have completed the previous step before moving on to the next.
This is the first step, connecting from your computer to the ors-ec2 server in the Public Subnet.
ors-ec2 (you can get this from the EC2 Dashboard).ec2-user.ors-keypair.pem file you downloaded.chmod 400 ors-keypair.pem

Once successfully connected to the server, install the necessary tools.
Update the system:
sudo yum update -y

Install Git:
sudo yum install -y git
Clone the project source code from GitHub:
git clone https://github.com/tuilatri/online-restaurant-system.git

Move into the backend directory:
cd online-restaurant-system/backend
Install Node.js and npm:
sudo dnf install -y nodejs

Check the versions to confirm successful installation:
node -v
npm -v
Install the project’s dependencies:
npm install

Move into the src directory and create the environment variable configuration file:
cd src
nano .env
Enter the database connection information:
In the nano editor, paste the following content and replace it with your information.
DB_HOST='your-rds-endpoint'
DB_USER='admin'
DB_PASSWORD='your-db-password'
DB_DATABASE='ors'
DB_PORT=3306


Configuring the .env file
Save and exit nano:
Ctrl + OEnter to confirm the file name.Ctrl + X to exit.Launch the application:
node createAdmin.js
node server.js

Test the application’s operation directly on the server:
Open a new terminal window in MobaXterm and connect to the same EC2 instance again, then use the curl command to test.
curl http://127.0.0.1:5000/api
If you receive the response Welcome to Dining Verse Backend API!, it means the application has started successfully!
If you update the code on GitHub but the changes do not appear on the web, follow these steps on the server:
Move into the backend directory:
cd online-restaurant-system/backend
Pull the latest code:
git pull origin main
Find the running Node.js process:
ps aux | grep node
Stop the old process using its PID:
kill -9 <PID>
Practical example:
[ec2-user@ip-10-0-144-101 backend]$ ps aux | grep node
ec2-user 3117 0.0 6.6 1127836 64896 pts/1 Sl+ 10:15 0:00 node server.js
[ec2-user@ip-10-0-144-101 backend]$ kill -9 3117
Restart the application:
npm run start