Overview
This solution deploys and runs a demo E-Commerce online store web app that is built with Node.js Express framework. The backend data store is stored on MongoDB. This app manages products and users online, and provides functions such as product navigation, shopping cart, and orders.
Reference Architecture
Steps
Deploy Resources
Use this main.tf file in Terraform to provision ECS, EIP, and ApsaraDB for MongoDB instances from this solution.
Go to the Alibaba Cloud ECS console and MongoDB console to see the instances you just created.
Set up Node.js and Other Basic Components on ECS
1. Log on to ECS via SSH:
ssh root@ECS_EIP
The default account name and password of the ECS instance are:
Account name:
Password:
Account name:
root
Password:
Aliyuntest123
2. Install Git client, Node.js:
dnf install -y git
dnf install -y npm
Deploy and Run the Web App
1. Check out the project
https://github.com/alibabacloud-howto/solution-mongodb-labs.git
from Github:git clone https://github.com/alibabacloud-howto/solution-mongodb-labs.git
2. Edit the
The default web port is 3000.
.env
file to set up the MongoDB connection URI (which can be found in the ApsaraDB for MongoDB console), then save the changes:cd ~/solution-mongodb-labs/e-commerce-application
vim .env
The default web port is 3000.
3. Build and install the app.
npm install
4. Start the web app.
cd ~/solution-mongodb-labs/e-commerce-application
npm start
5. Visit
http://ECS_EIP:3000
in a web browser to open the web app.
6. 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 run dev
beforehand. Then, run the following command to install PM2 and start the web app: cd ~/solution-mongodb-labs/e-commerce-application
npm i -g pm2
pm2 start app.js
7.Visit
http://ECS_EIP:3000
again in the web browser to see the web app. You can sign up an Admin
account to manage products, and register a common user account to test the functions of the web app.
Install Mongoku on ECS to Manage Data on MongoDB
1. Install the open-source MongoDB Web Admin tool Mongoku on ECS to manage data on MongoDB:
cd ~
npm install -g mongoku
mongoku start --pm2
2. Visit
You can add the MongoDB connection URI as the server to navigate and manage the data for this e-commerce web app via Mongoku.
http://ECS_EIP:3100
again in the web browser to visit the Mongoku Web Admin. Mongoku uses port 3100 for the web app by default.You can add the MongoDB connection URI as the server to navigate and manage the data for this e-commerce web app via Mongoku.