×
Community Blog Deploy Application Stack Parse Server with MongoDB on Alibaba Cloud

Deploy Application Stack Parse Server with MongoDB on Alibaba Cloud

This tutorial explains how to install and deploy Parse Server with MongoDB on Alibaba Cloud.

You can access the tutorial artifact, including the deployment script (Terraform), related source code, sample data, and instruction guidance from this GitHub project.

For more tutorials about Alibaba Cloud Database, please refer to this link.

Database Deployment Tutorials Series: https://community.alibabacloud.com/series/118

Overview

Parse is the complete application stack for building applications faster with object and file storage, user authentication, push notifications, a dashboard, and more right out of the box. Compared to Google Firebase, Parse is a bunch of pure open-source projects for application building and life cycle management.

Click this following link to read more about Firebase vs. Parse Server by Back4App.

This tutorial explains how to install and deploy Parse Server with MongoDB on Alibaba Cloud.

Deployment architecture:

1

Index

Step 1. Use Terraform to Provision ECS and the MongoDB Database on Alibaba Cloud

If this is your first time using Terraform, please refer to this link to learn how to install and use Terraform on different operating systems.

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 it.

2

After the Terraform script execution is finished, the ECS instance information is listed as below:

3

  • eip_ecs: The public EIP of the ECS for the parse server host

For the MongoDB instance information, please go to the Alibaba Cloud MongoDB web console to get the connection URI:

4
5

The username and password are root and N1cetest by default, which are preset in the Terraform provision script. If you've already changed it, please update 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.

Step 2. Install and Deploy Parse-Server with ECS and MongoDB

Please log on to ECS with ECS EIP. The password is N1cetest by default, which is preset in the Terraform provision script in Step 1. If you've already changed it, please update accordingly.

ssh root@<ECS_EIP>

6

Execute the following commands to install Node.js. Parse Server requires Node 8 or newer. Here we install the Node 12:

wget https://npm.taobao.org/mirrors/node/v12.0.0/node-v12.0.0-linux-x64.tar.xz
tar -xvf node-v12.0.0-linux-x64.tar.xz
rm node-v12.0.0-linux-x64.tar.xz  -f
mv node-v12.0.0-linux-x64/ node
ln -s ~/node/bin/node /usr/local/bin/node
ln -s ~/node/bin/npm /usr/local/bin/npm

7

Execute the following commands to install parse-server:

npm install -g parse-server
ln -s ~/node/lib/node_modules/parse-server/bin/parse-server /usr/local/bin/parse-server

8

Execute the following commands to verify the Node modules have been installed successfully:

ll /usr/local/bin/

9

Then, execute the following command to start the installed parse-server:

parse-server --appId <APP_ID> --masterKey <MASTER_KEY> --databaseURI <MONGODB_URL> &

Please replace the parameters accordingly:

  • <APP_ID>: Your application ID
  • <MASTER_KEY>: Uour application secret key
  • <MONGODB_URL>: The MongoDB URL of the provisioned MongoDB instance in Step 1.

For example, execute the command like this:

parse-server --appId my_application_id --masterKey 12345678 --databaseURI mongodb://root:N1cetest@dds-3ns6f7171a6961441.mongodb.rds.aliyuncs.com:3717,dds-3ns6f7171a6961442.mongodb.rds.aliyuncs.com:3717/admin?replicaSet=mgset-56568439 &

10

Now, the parse-server is running and listening the service port 1337. The service API URL is http://<ECS_EIP>:1337/parse.

Step 3. Install Parse-Dashboard on ECS

The parse-server is ready for serving the application now. You can go to Step 4 to verify and interact with parse-server directly. However, we highly recommend installing parse-dashboard for administration and application monitoring on parse-server.

For more information about parse-dashboard, please visit https://github.com/parse-community/parse-dashboard.

Now, execute the following commands to install parse-dashboard:

npm install -g parse-dashboard
ln -s ~/node/lib/node_modules/parse-dashboard/bin/parse-dashboard /usr/local/bin/parse-dashboard
ll /usr/local/bin/

11

Then, execute the following commands to create a configuration file to start the dashboard of the previous application started on parse-server:

cd ~/node/lib/node_modules/parse-dashboard/bin
vim parse-dashboard.json

Input the following content into the file parse-dashboard.json. Please remember to:

  • replace <ECS_EIP> with the provisioned ECS EIP in Step 1
  • replace <APP_ID> with your application ID used when starting parse-server in Step 2
  • replace <MASTER_KEY> with your application secret key used when starting parse-server in Step 2

We preset the user name and password as admin and admin for parse-dashboard log on. You can change it accordingly.

{
  "apps": [
    {
      "serverURL": "http://<ECS_EIP>:1337/parse",
      "appId": "<APP_ID>",
      "masterKey": "<MASTER_KEY>",
      "appName": "MyApp",
      "supportedPushLocales": ["en", "ru", "fr"]
    }
  ],
  "users": [
    {
      "user":"admin",
      "pass":"admin"
    }
  ]
}

12

Then, execute the following command to start the parse-dashboard:

parse-dashboard --dev --config parse-dashboard.json &

13

Now, the parse-dashboard has been started. Please visit http://<ECS_EIP>:4040.

14

Log on to see the dashboard of the application:

15

Step 4. Post Application Data to Verify Parse-Server and Parse-Dashboard

Now, the parse-server and parse-dashboard are ready. Let's post some data to simulate the interaction with the parse-server.

Please execute the following commands on ECS and check the response. Please remember to replace the my_application_id with the defined application ID when starting the parse-server.

curl -X POST \
-H "X-Parse-Application-Id: my_application_id" \
-H "Content-Type: application/json" \
-d '{"score":100,"playerName":"Sean Plott","cheatMode":false}' \
http://localhost:1337/parse/classes/GameScore

curl -X POST \
-H "X-Parse-Application-Id: my_application_id" \
-H "Content-Type: application/json" \
-d '{"score":120,"playerName":"Sean Plott","cheatMode":false}' \
http://localhost:1337/parse/classes/GameScore

curl -X POST \
-H "X-Parse-Application-Id: my_application_id" \
-H "Content-Type: application/json" \
-d '{"score":999,"playerName":"Julian","cheatMode":true}' \
http://localhost:1337/parse/classes/GameScore

curl -X GET \
  -H "X-Parse-Application-Id: my_application_id" \
  http://localhost:1337/parse/classes/GameScore

16

Go to the parse-dashboard and refresh the web page to see the posted application data:

17

0 0 0
Share on

ApsaraDB

168 posts | 14 followers

You may also like

Comments

ApsaraDB

168 posts | 14 followers

Related Products