This article provides a general overview of using Terraform to achieve the goal. If you prefer using a graphical interface, you can refer to the following article:
Starter Guide | Build E-Commerce Web App Using MongoDB and Node.js in One Click
You can access the tutorial artifact, including deployment script (Terraform), related source code, sample data, and instruction guidance from this GitHub project.
Please refer to this link for more tutorials around Alibaba Cloud Database
This is a demo e-commerce online store web application built with Node.js Express Framework. The backend data store is on MongoDB. In this tutorial, I will explain how to build and deploy on Alibaba Cloud ECS and MongoDB.
These are the key features of this web application:
admin
accountDeployment Architecture:
Run the Terraform script to initialize the resources. (In this tutorial, we use MongoDB as a backend database, so ECS and MongoDB are included in the Terraform script.) Please specify the necessary information and region to deploy.
After the Terraform script execution finishes, the ECS instance information is listed below:
eip_ecs
: The public EIP of the ECS for web app hostFor the MongoDB instance information, please go to the Alibaba Cloud MongoDB web console to get the connection URI.
By default, the username and password are root
and N1cetest
, which are preset in the Terraform provision script. If you've already changed it, please update it accordingly.
Please replace the string ****
with N1cetest
in the connection URI string, such as:
mongodb://root:N1cetest@dds-xxxx.mongodb.rds.aliyuncs.com:3717,dds-xxxx.mongodb.rds.aliyuncs.com:3717/admin?replicaSet=mgset-55560033
The MongoDB connection URI will be used later when deploying the web application.
Please log on to ECS with ECS EIP
. By default, the password is N1cetest
, which is preset in the Terraform provision script in Step 1. If you've already changed it, please update it accordingly.
ssh root@<ECS_EIP>
Execute the following commands to install Git client, Node.js:
dnf install -y git
dnf install -y npm
Execute the command to check out the project on GitHub.
git clone https://github.com/alibabacloud-howto/solution-mongodb-labs.git
Execute the commands and edit the .env
file to set up the MongoDB connection URI (from Step 1) and save the changes to the .env
file. By default, I will use 3000
as the web app port. If you'd like to change it, please update it accordingly.
cd ~/solution-mongodb-labs/e-commerce-application
vim .env
Execute the following commands to build and install the app:
npm install
Now, execute the following commands to start the web app:
cd ~/solution-mongodb-labs/e-commerce-application
npm start
Then, open http://<ECS_EIP>:3000/
in a web browser to visit the web app.
Usually, we need to run the Node.js app as a daemon process. Now, install pm2 to start or manage the lifecycle of the Node.js web app.
First, enter Ctrl + C
to stop the web app process started by executing npm start
beforehand. Then, execute the following commands to install pm2 and start the web app via pm2.
cd ~/solution-mongodb-labs/e-commerce-application
npm i -g pm2
pm2 start app.js
Then, open http://<ECS_EIP>:3000/
again in a web browser to visit the web app.
Let's do some simple operations on it:
admin
account for managing productAdd Product. Let's add iPhone 13 product family for the demo. For the product image URL, I will use the following URLs. Also, the product can be edited.
Execute the following commands to install the open-source MongoDB Web Admin tool Mongoku on ECS to manage data on MongoDB:
cd ~
npm install -g mongoku
mongoku start --pm2
Then, open http://<ECS_EIP>:3100/
again in a web browser to visit the Mongoku Web Admin. Mongoku uses the 3100
port for web apps by default. I've already set this in the security group rule within the Terraform script.
Now, we can add the MongoDB connection URI here as the server to navigate and manage the data for this online store e-commerce web app via Mongoku. Please enjoy.
Create a Social Web App with Next.js and MongoDB on Alibaba Cloud
Best Practices for Setting the Parameter performance_schema: Overview
ApsaraDB - May 15, 2024
Prof - July 25, 2018
Alibaba Clouder - January 4, 2019
Alibaba Clouder - November 14, 2017
Alibaba Clouder - March 29, 2019
Alibaba Clouder - August 29, 2018
Elastic and secure virtual cloud servers to cater all your cloud hosting needs.
Learn MoreA secure, reliable, and elastically scalable cloud database service for automatic monitoring, backup, and recovery by time point
Learn MoreSet up an all-in-one live shopping platform quickly and simply and bring the in-person shopping experience to online audiences through a fast and reliable global network
Learn MoreAlibaba Cloud e-commerce solutions offer a suite of cloud computing and big data services.
Learn MoreMore Posts by ApsaraDB