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:
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 host
For 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
N1cetest, which are preset in the Terraform provision script. If you've already changed it, please update it accordingly.
Please replace the string
N1cetest in the connection URI string, such as:
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.
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:
Now, execute the following commands to start the web app:
cd ~/solution-mongodb-labs/e-commerce-application npm start
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.
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
http://<ECS_EIP>:3000/ again in a web browser to visit the web app.
Let's do some simple operations on it:
adminaccount for managing product
Add 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
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.
Prof - July 25, 2018
Alibaba Clouder - January 4, 2019
Alibaba Clouder - November 14, 2017
Alibaba Clouder - March 29, 2019
ApsaraDB - October 28, 2021
Alibaba Clouder - August 29, 2018
An online computing service that offers elastic and secure virtual cloud servers to cater all your cloud hosting needs.Learn More
A secure, reliable, and elastically scalable cloud database service for automatic monitoring, backup, and recovery by time pointLearn More
Set 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 networkLearn More
Block-level data storage attached to ECS instances to achieve high performance, low latency, and high reliabilityLearn More
More Posts by ApsaraDB