Parse Server:
Parse Server is an open source Backend-as-a-Service(BaaS) framework initially developed by Facebook. The platform now has an active and robust community of fanatical developers
Let's Start installation of Parse server:
Prerequisites: Before we Start Parse installation we need following prerequisites:
- NodeJS
- MongoDB
To install Mongodb at Ubuntu 16.04, Please follow the below link.
Step 2- Install NodeJS:
NodeJS installation: First we need to add node.js ppa to our system and perform the nodejs installation with python, let's follow the steps below
Install Python properties
sudo apt-get install build-essential git python-software-properties
ADD NodeJS Repo :
curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
Your output should be like below Filtered screenshot
Install NodeJS:
Please run below command at terminal to start the nodejs installation
apt-get install nodejs
Your installation screen should be like below
Step 3- Download and setup Parse Server:
Now download the parse server from the link below
3A-Change the directory first
root@Server16:~# cd /opt/
3B-Now download parse server
root@Server16:/opt# git clone https://github.com/ParsePlatform/parse-server-example.git
3C-Now Cd to the downloaded folder- parse-server-example and install all nodejs dependencies using command npm install
root@Server16:/opt# cd parse-server-example/
root@Server16:/opt/parse-server-example# npm install
Filtered ouput
3D- Allow User access on the DB- Please skip this step if authentication is not enabled on your mongodb.
If your MongoDB has authentication enabled then we need to setup an account and grant access on db dev
Logon to mongo shell with user have admin level access
mongo -u amar -p
root@Server16:/opt/parse-server-example# mongo -u amar -p
MongoDB shell version v3.6.3
Enter password: *******
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.6.3
Grant permission to user on database dev
Run below script to add user amar and grant readWrite access on db to dev
Run below script to add user amar and grant readWrite access on db to dev
> use dev
switched to db dev
> db.createUser({user:"amar", pwd:"redhat", roles:[{role:"readWrite", db:"dev"}]})
Successfully added user: {
"user" : "amar",
"roles" : [
{
"role" : "readWrite",
"db" : "dev"
}
]
}
> exit
root@Server16:/opt# vi index.js
Modify you file with Mongodb url, App_ID and Master_Key
var databaseUri = 'mongodb://amar:redhat@localhost:27017/dev';
//
//if (!databaseUri) {
// console.log('DATABASE_URI not specified, falling back to localhost.');
//}
var api = new ParseServer({
databaseURI: databaseUri || 'mongodb://amar:redhat@localhost:27017/dev',
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID || 'myappkey',
masterKey: process.env.MASTER_KEY || 'mymasterkey', //Add your master key here. Keep it secret!
serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse', // Don't forget to change to https if needed
liveQuery: {
classNames: ["Posts", "Comments"] // List of classes to support for query subscriptions
}
});
Save and Exit from the file
Your index.js file looks like below screenshot.
Step 4- Start Parse Server
After all the configuration changes, let's start the parse server
npm start
root@Server16:/opt/parse-server-example# npm start
> parse-server-example@1.4.0 start /opt/parse-server-example
> node index.js
parse-server-example running on port 1337.
Your terminal output should be similar this
Parse server installation has completed successfully.
Step 5- keep running parse server in the terminal background
By default npm start command works until you are logged in to terminal, once you interrupt the running process or close the terminal. Your parse server will stop running. Let's use some trick to run npm start command in the background.
nohup start npm &
Step 6-Test Parse Server:
After setting up all the configuration, let's test parse server. First, add some value to parse server using curl command line. This will connect to parse server and records will be save to mongodb database. Change MyApp_ID with yours
curl -X POST \
-H "X-Parse-Application-Id: myappkey" \
-H "Content-Type: application/json" \
-d '{"score":1337,"InventoryName":"Desktops","cheatMode":false}' \
http://localhost:1337/parse/classes/Inventory
OUTPUT
{"objectId":"UIWRBpyPyy","createdAt":"2018-03-12T10:51:30.639Z"}
curl -X GET -H "X-Parse-Application-Id: myappkey"\
http://localhost:1337/parse/classes/Inventory
OUTPUT
{"results":[{"objectId":"UIWRBpyPyy","score":1337,"InventoryName":"Desktops","cheatMode":false,"createdAt":"2018-03-12T10:51:30.639Z","updatedAt":"2018-03-12T10:51:30.639Z"}]}
Generally, we can keep running parse server using nohup command. but incase we required a server reboot that time parse server will not come online automatically. let enable this command to run during system boot.
Edit /etc/rc.local File.
Vi /etc/rc.local
Append following red highligted line before exit 0cd /opt/parse-server-example
nohup npm start &
exit 0
Save and exit from the file. Now, parse server will start auto during system boot.
We have successfully installed and configured parse server on Ubuntu 16.04 LTS. Let’s setup Parse Dashboard to access Parse server data.
No comments:
Post a Comment