// Tutorial //

How To Run Parse Server on Ubuntu 14.04

Published on February 3, 2016
Default avatar
By Brennen Bearnes
Developer and author at DigitalOcean.
How To Run Parse Server on Ubuntu 14.04

Introduction

Parse is a Mobile Backend as a Service platform, owned by Facebook since 2013. In January of 2016, Parse announced that its hosted services would shut down in January of 2017.

In order to help its users transition away from the service, Parse has released an open source version of its backend, called Parse Server, which can be deployed to environments running Node.js and MongoDB.

This guide supplements the official documentation with detailed instructions for installing Parse Server on an Ubuntu 14.04 system, such as a DigitalOcean Droplet. It is intended first and foremost as a starting point for Parse developers who are considering migrating their applications, and should be read in conjunction with the official Parse Server Guide.

Prerequisites

This guide assumes that you have a clean Ubuntu 14.04 system, configured with a non-root user with sudo privileges for administrative tasks. You may wish to review the guides in the New Ubuntu 14.04 Server Checklist series.

Additionally, your system will need a running instance of MongoDB. You can start by working through How to Install MongoDB on Ubuntu 14.04. MongoDB can also be installed automatically on a new Droplet by adding this script to its User Data when creating it. Check out this tutorial to learn more about Droplet User Data.

Once your system is configured with a sudo user and MongoDB, return to this guide and continue.

Step 1 — Install Node.js and Development Tools

Begin by changing the current working path to your sudo user’s home directory:

  1. cd ~

NodeSource offers an Apt repository for Debian and Ubuntu Node.js packages. We’ll use it to install Node.js. NodeSource offers an installation script for the the latest stable release (v5.5.0 at the time of this writing), which can be found in the installation instructions. Download the script with curl:

  1. curl -sL https://deb.nodesource.com/setup_5.x -o nodesource_setup.sh

You can review the contents of this script by opening it with nano, or your text editor of choice:

  1. nano ./nodesource_setup.sh

Next, run nodesource_setup.sh. The -E option to sudo tells it to preserve the user’s environment variables so that they can be accessed by the script:

  1. sudo -E bash ./nodesource_setup.sh

Once the script has finished, NodeSource repositories should be available on the system. We can use apt-get to install the nodejs package. We’ll also install the build-essential metapackage, which provides a range of development tools that may be useful later, and the Git version control system for retrieving projects from GitHub:

  1. sudo apt-get install -y nodejs build-essential git

Step 2 — Install an Example Parse Server App

Parse Server is designed to be used in conjunction with Express, a popular web application framework for Node.js which allows middleware components conforming to a defined API to be mounted on a given path. The parse-server-example repository contains a stubbed-out example implementation of this pattern.

Retrieve the repository with git:

  1. git clone https://github.com/ParsePlatform/parse-server-example.git

Enter the parse-server-example directory you just cloned:

  1. cd ~/parse-server-example

Use npm to install dependencies, including parse-server, in the current directory:

  1. npm install

npm will fetch all of the modules required by parse-server and store them in ~/parse-server-example/node_modules.

Step 3 — Test the Sample Application

Use npm to start the service. This will run a command defined in the start property of package.json. In this case, it runs node index.js:

  1. npm start
Output
> parse-server-example@1.0.0 start /home/sammy/parse-server-example > node index.js DATABASE_URI not specified, falling back to localhost. parse-server-example running on port 1337.

You can terminate the running application at any time by pressing Ctrl-C.

The Express app defined in index.js will pass HTTP requests on to the parse-server module, which in turn communicates with your MongoDB instance and invokes functions defined in ~/parse-server-example/cloud/main.js.

In this case, the endpoint for Parse Server API calls defaults to:

http://your_server_IP/parse

In another terminal, you can use curl to test this endpoint. Make sure you’re logged into your server first, since these commands reference localhost instead of a specific IP address.

Create a record by sending a POST request with an X-Parse-Application-Id header to identify the application, along with some data formatted as JSON:

curl -X POST \
  -H "X-Parse-Application-Id: myAppId" \
  -H "Content-Type: application/json" \
  -d '{"score":1337,"playerName":"Sammy","cheatMode":false}' \
  http://localhost:1337/parse/classes/GameScore
Output
{"objectId":"fu7t4oWLuW","createdAt":"2016-02-02T18:43:00.659Z"}

The data you sent is stored in MongoDB, and can be retrieved by using curl to send a GET request:

  1. curl -H "X-Parse-Application-Id: myAppId" http://localhost:1337/parse/classes/GameScore
Output
{"results":[{"objectId":"GWuEydYCcd","score":1337,"playerName":"Sammy","cheatMode":false,"updatedAt":"2016-02-02T04:04:29.497Z","createdAt":"2016-02-02T04:04:29.497Z"}]}

Run a function defined in ~/parse-server-example/cloud/main.js:

curl -X POST \
  -H "X-Parse-Application-Id: myAppId" \
  -H "Content-Type: application/json" \
  -d '{}' \
  http://localhost:1337/parse/functions/hello
Output
{"result":"Hi"}

Step 4 — Configure Sample Application

In your original terminal, press Ctrl-C to stop the running version of the Parse Server application.

As written, the sample script can be configured by the use of six environment variables:

Variable Description
DATABASE_URI A MongoDB connection URI, like mongodb://localhost:27017/dev
CLOUD_CODE_MAIN A path to a file containing Parse Cloud Code functions, like cloud/main.js
APP_ID A string identifier for your app, like myAppId
MASTER_KEY A secret master key which allows you to bypass all of the app’s security mechanisms
PARSE_MOUNT The path where the Parse Server API should be served, like /parse
PORT The port the app should listen on, like 1337

You can set any of these values before running the script with the export command. For example:

  1. export APP_ID=fooApp

It’s worth reading through the contents of index.js, but in order to get a clearer picture of what’s going on, you can also write your own shorter version of the example . Open a new script in your editor:

  1. nano my_app.js

And paste the following, changing the highlighted values where desired:

~/parse-server-example/my_app.js
var express = require('express');
var ParseServer = require('parse-server').ParseServer;

// Configure the Parse API
var api = new ParseServer({
  databaseURI: 'mongodb://localhost:27017/dev',
  cloud: __dirname + '/cloud/main.js',
  appId: 'myOtherAppId',
  masterKey: 'myMasterKey'
});

var app = express();

// Serve the Parse API on the /parse URL prefix
app.use('/myparseapp', api);

// Listen for connections on port 1337
var port = 9999;
app.listen(port, function() {
    console.log('parse-server-example running on port ' + port + '.');
});

Exit and save the file, then run it with Node.js:

  1. node my_app.js
Output
parse-server-example running on port 9999.

Again, you can press Ctrl-C at any time to stop my_app.js. As written above, the sample my_app.js will behave nearly identically to the provided index.js, except that it will listen on port 9999, with Parse Server mounted at /myparseapp, so that the endpoint URL looks like so:

http://your_server_IP:9999/myparseapp

And it can be tested with curl like so:

  1. curl -H "X-Parse-Application-Id: myOtherAppId" http://localhost:9999/myparseapp/classes/GameScore`

Conclusion

You should now know the basics of running a Node.js application like Parse Server in an Ubuntu environment. Fully migrating an app from Parse is likely to be a more involved undertaking, requiring code changes and careful planning of infrastructure.

For much greater detail on this process, see the second guide in this series, How To Migrate a Parse App to Parse Server on Ubuntu 14.04. You should also reference the official Parse Server Guide, particularly the section on migrating an existing Parse app.


Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in our Questions & Answers section, find tutorials and tools that will help you grow as a developer and scale your project or business, and subscribe to topics of interest.

Sign up

Tutorial Series: How To Host Parse Server

Parse Server is an open source implementation of the Parse API for mobile applications. It can be be deployed to a range of environments running Node.js and MongoDB. This series focuses on running Parse Server infrastructure in generic GNU/Linux environments such as those provided by DigitalOcean.

About the authors
Default avatar
Developer and author at DigitalOcean.

Still looking for an answer?

Was this helpful?
10 Comments

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Since FB cause all this hassle for a lot of people that trusted them, why not release the whole thing including the dashboard and let the community really take over??? I still cannot believe that FB just drop us like that…

I have done it. But my website show(http://120.27.102.9:1337/parse): {“error”:“unauthorized”} I think it do not connect the mongodb do you know what happen~

I made a video walkthrough of this tutorial for anyone interested :) https://www.youtube.com/watch?v=Yhc_fzSi0kk

thank you for this detailed explanation. One question though. Using parse-server-example will install the 1.00 version. And the parse-server (https://github.com/ParsePlatform/parse-server) is now at version 2.0.8.

how do we upgrade to that version ? (since more bugs have been fixed). Thank you

Nice introduction, but does not work without extra efforts:

  • Port 9999 is blocked:
$ The "ufw" firewall is enabled. All ports except for 22, 80, and 443 are BLOCKED
  • serverURL is missing in my_app.js, a setting like that is needed inside ParseServer setup:
serverURL: 'http://localhost:1337/parse'

You can use also www.back4app.com to deploy Parse Server.

I’m stuck on this part.

http://your_server_IP(replaced with my droplet ip)/parse

I cant seem to call the page.

here is what i got when i call “nam install”

parse-server-example@1.4.0 start /root/parse-server-example node index.js

DATABASE_URI not specified, falling back to localhost. parse-server-example running on port 1337.

please help

Hi, thanks for the great tutorial. It was all going really well until I reached the point of running “npm install” in my trial folder. I get a whole bunch of errors when it runs and then the final error log output comes up as 26 error Linux 3.10.0-327.10.1.el7.x86_64 27 error argv “/root/.nvm/v6.3.1/bin/node” “/root/.nvm/v6.3.1/bin/npm” “bugs” “pg-promise” 28 error node v6.3.1 29 error npm v3.10.3 30 error path xdg-open 31 error code ENOENT 32 error errno ENOENT 33 error syscall spawn xdg-open 34 error enoent spawn xdg-open ENOENT 35 error enoent spawn xdg-open ENOENT 35 error enoent This is most likely not a problem with npm itself 35 error enoent and is related to npm not being able to find a file. 36 verbose exit [ 1, true ]

Which is really frustrating because I’ve tried updating all my yum repositories and cleaned up everything I can think of to no avail. If it helps at all the raw cli return after “npm install” was all looking good until the last 15 lines or so where I get npm ERR! Linux 3.10.0-327.10.1.el7.x86_64 npm ERR! argv “/root/.nvm/v6.3.1/bin/node” “/root/.nvm/v6.3.1/bin/npm” “install” npm ERR! node v6.3.1 npm ERR! npm v3.10.3 npm ERR! code ELIFECYCLE

npm ERR! pg-promise@5.2.5 postinstall: node install.js npm ERR! Exit status 8 npm ERR! npm ERR! Failed at the pg-promise@5.2.5 postinstall script ‘node install.js’. npm ERR! Make sure you have the latest version of node.js and npm installed. npm ERR! If you do, this is most likely a problem with the pg-promise package, npm ERR! not with npm itself. npm ERR! Tell the author that this fails on your system: npm ERR! node install.js npm ERR! You can get information on how to open an issue for this project with: npm ERR! npm bugs pg-promise npm ERR! Or if that isn’t available, you can get their info via: npm ERR! npm owner ls pg-promise npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request: npm ERR! /root/Parse/npm-debug.log npm ERR! code 1

Any thoughts or tricks would be hugely appreciated.

Thanks!

Anyone have any ideas or pointers on getting parse-server to handle multiple apps?

My initial thoughts are to house an instance of Mongo on one droplet that will contain all of my various app databases, and then on a second droplet install parse-server and create a new my_app.js style file for each app that I want to run?

Or can I just define different api vars for each app maybe and name them after my app?

Thanks

The complete Parse-Server and Parse-Dashboard Tutorials with DigitalOcean! https://www.youtube.com/playlist?list=PLOxfUzCCcGSDQGpSJFR4_5-s0V79XES5B