Deploying Frontend and Backend

In the previous section, we uploaded the files to the VSCode SSH server under the Ubuntu account and unzipped the file into a directory in /root.

image.png

We will now proceed to deploy the Frontend and Backend.

1. Deploying the Backend

Navigate to the ecommerce-fullstack-netcore-react/backend/ directory and run:

dotnet restore

This command is used to install the required dependencies.

image.png

Then, start the Backend using the following command:

dotnet run

The CLI will indicate that the Backend is running on port 5214.

image.png Access port 5214/swagger in your browser to check the running results and confirm that the Backend is running successfully!

image.png

Test a few functionalities.

image.png

We encountered an error due to the database not being set up. You will work on this in the next section!

When using the command above, if we exit using Ctrl + C, the Backend will stop running.

image.png

We will proceed to run the Backend in the background by using:

nohup dotnet run > run_bg.txt 2>&1 &

image.png

And the result is that Swagger continues to run normally!

image.png

2. Deploying the Frontend

Navigate to the frontend directory:

cd /root/ecommerce-fullstack-netcore-react/frontend/

image.png

Install the libraries using the following command:

npm install

🡇 Content 🡇

If you encounter issues running npm i,

image.png

You need to run the following command:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

And the issue was successfully resolved!

image.png

🡅 Content 🡅

Proceed to start the Frontend project with:

npm start

image.png

After starting, check port 3000 in your browser to verify that the website has started successfully!

image.png

image.png

However, like the Backend, there is an issue where the website will immediately stop if we use Ctrl + C. The solution is to run it in the background. At this step, you can use nohup as mentioned above.

Another approach we can use is pm2.

Proceed to install pm2. You can refer to the installation link here: PM2 - Quick Start (keymetrics.io)

npm install pm2@latest -g

image.png

Then, start the FE project with pm2:

pm2 start npm --name "ecommerce" -- run "start"

image.png

The result is that the website continues to run normally. Below, as we haven’t set up SQL, the products are not displayed.

image.png

Additionally, pm2 has monitoring functionality:

pm2 monit

image.png

Thus, we have successfully deployed the Frontend and Backend.