How To Migrate Your Parse App To Parse Server With Heroku And mLab [GUIDE]

Written by Reinder de Vries on January 31 2016 in App Development

How To Migrate Your Parse App To Parse Server With Heroku And mLab [GUIDE]

On January 28th Parse announced it will be shutting down its service. They’re winding down the done-for-you Platform-as-a-service, fully retiring it on January 28, 2017.

That’s bad news for over 500.000 developers who relied on the service since 2011. Parse was acquired in 2013 by Facebook for $ 85 million. Back then it was a risky acquisition, which Facebook needed to get a foothold in the mobile market.

Facebook’s recent earnings report shows a growth in mobile advertising revenue of 52%, comparing Q4 of 2014 and 2015, which clearly shows they’ve landed in mobile. With the rise in competition of cloud services by the likes of Amazon, Microsoft and Google, you could argue Facebook doesn’t need Parse anymore.

App developers that use Parse have several options to migrate. Alternatives include Firebase, built.io and the new Parse Server stack.

This guide will show you how you can migrate your app from Parse to Parse Server by making use of the free Heroku and mLab services. The guide starts with the setup of the Paws app, a minimal Instagram-like iOS app (cat pictures!).

You’ll set up the app, migrate it to mLab, then start a Heroku instance and connect it to the app. Prior I’ll explain a bit about the Parse and Parse Server architecture.

This code guide can be used for app makers who want to migrate their app from Parse to Parse Server. It’s also suitable for app makers who have never used Parse (and don’t have a Parse account) and wish to set up a fresh Parse Server app.

Let’s get started!

0. Overview: What Ingredients Do You Need?

Parse is technically a Backend-as-a-Service provider. It hosts a service you can use to store structured information and provides you with an API endpoint you can use to create and edit your app’s data. Parse has many SDKs for platforms such as iOS, Android and NodeJS (JavaScript).

In a diagram, this is what the Parse stack looks like (Figure 1):

Figure 1, 2 and 3
Figure 1, 2 and 3

As an app maker, you only had to code your app’s client-side code and manage the data in a easy-to-use administration tool. No need to worry about scaling the back-end, building indices or managing your data at a microlevel. You could essentially tap your app into a spreadsheet, and never worry about it. Your app connected through the high-level SDK to Parse, and Parse managed its own databases.

When migrating to Parse Server, the architecture is different (Figure 2). Instead of only working with the Parse SDK, you manage your own Heroku instance that runs Parse Server, and manage your own MongoDB database that connects to Parse Server. You’re responsible for scaling and maintaining your own back-end.

If you map out different back-end architectures on a scale from “hard” to “easy”, and “unmanaged” to “done-for-you”, you end up with Figure 3. As you can see, it requires dedicated sysops time to run a bare-metal server or Virtual Private Server (VPS, or cloud server), while it takes zero effort for the app maker to run the Parse BaaS. Somewhere in the middle between VPS and Parse you’ll find Heroku and mLab (and equivalents), not as hard as maintaining a VPS, but not as easy as the original Parse.

Parse strongly recommends you to migrate to Parse Server as soon as possible. In the diagram you see a dotted line, which indicates an intermediary state in which you still communicate with the Parse back-end, but in which Parse communicates with your self-hosted MongoDB database.

This allows for a two-step migration:

  1. First, you set up a MongoDB database (on mLab, or equivalent) and let Parse send your data to it. Your current app clients don’t require a code change, because the Parse API endpoint doesn’t change.
  2. Second, you set up Parse Server (on Heroku, or equivalent) and connect it to your MongoDB database. You publish an update for your app that points to the new Parse Server API endpoint. App users that didn’t update will use the MongoDB database through the original Parse, and updated users will use the new Parse Server. In either case, your app will point to a single database. While the migration is taking place, Parse will keep track of additions and will sync them after the initial migration completes.

Both steps are documented in this code guide. Even if you didn’t use Parse before today, you can use this code guide to learn how to set up a fresh Parse Server for your app.

While it may seem like an obvious migration schedule, it’s important to take note of the changes in architecture. You can read more on this in the conclusion of this code guide.

Learn how to build iOS apps

Get started with iOS 12 and Swift 4

Sign up for our iOS development course Zero to App Store and learn how to build professional iOS 12 apps with Swift 4 and Xcode 10.

1. Getting Started: Set Up The “Paws” App

Alright, first lets get started with the original Paws app. The app is part of a code guide originally published on AppCoda.com.

The Paws app is a minimal Instagram-clone that shows pictures of cats in a vertical timeline. Users can upvote a cat picture by double-tapping on its image. The project uses the Parse and ParseUI pods (with CocoaPods), and relies on the now shut down Parse.

In this code guide, you’ll first set up the Paws project as if it were fully reliant on Parse (an “existing project migration”) and then two-step migrate it to Parse Server.

Getting The Paws Code From GitHub

First, download the Paws Xcode project from GitHub at https://github.com/reinderdevries/Paws. Download the ZIP and unzip it in a convenient location. If you have Git installed, you can of course also clone the project.

Use Terminal to cd into the project’s root directory, like this:

Terminal: cd into Paws directory
Terminal: cd into Paws directory

Next up, make sure you’ve got the latest versions of the pods used in the project. In the same root directory, type this on the command-line:

$ pod update

(Note: you can omit the $, it just indicates the code block above should be input on the command-line. Make sure you press the Enter key after you type in a Terminal command.)

If you don’t have CocoaPods installed on your Mac, follow the steps documented here to install it.

CocoaPods will now read the Podfile, which contains a reference to pods Parse and ParseUI, and attempts to download their latest versions. It also builds the pods and adds them to our Paws.xcworkspace workspace file.

You’re likely to see something similar to the following output in Terminal:

Terminal: pod update
Terminal: pod update

Next up, open the Paws.xcworkspace file. You can use Finder to locate the file, or open Xcode and then open the right workspace. It’s important you don’t open the Paws.xcodeproj file, but instead use the workspace file.

Press the Command-B keys to build the project, and verify that the project doesn’t generate any errors. If you were to run the project in its current state on your iPhone or the iOS Simulator, it wouldn’t run, because the configuration parameters haven’t been set. We’ll do that in a minute!

Uploading The App Data To Parse

Because we’re recreating an existing Parse project, we need to update the app’s data to Parse. We could of course import it right into the MongoDB database we are creating in the next step, but that would defeat the purpose of experiencing what it’s like to migrate an existing app.

  • First, download the following file: paws_data_json.zip. It contains the data for the app, including the URLs of the cat photos, photo credit information, and the names of the cats.
  • Second, unzip the file in a convenient location.

Next up, go to parse.com/login and log in with your account credentials.

Note: Unfortunately, if you don’t have an account already you can’t create a new one due to the shutdown of the Parse service. Don’t worry, you can still use Parse Server! Skip ahead of part 2, creating a MongoDB database with mLab, and follow the special instructions on importing the app data in mLab.

On your Parse dashboard, click the Create a new app button. Name the app “Paws” and set its database type to Parse Data. Once the app is created, you’ll be taken to the Browser.

Parse Dashboard
Parse Dashboard

Click on the ... three-dotted button in the bottom-left of the interface (see image above), then choose Leave Beta. This will take you to the previous version of the Parse Dashboard UI. Why the change? Well, for some reason the new UI doesn’t have a button to import data into Parse…

Next, locate your Paws app in the old UI and make sure to navigate to Parse Core. Your screen should now look like this:

Old Parse Core
Old Parse Core

Next, do this:

  • First, click the Import button. A dialog box appears.
  • Then, click Browse. Locate the data file you previously unzipped. Make sure to upload the .json file, not the .zip file.
  • Then, once the file is uploaded, choose Custom for Collection Type and name the collection Cat.
  • Finally, click Finish Import.

Connecting Parse To The Paws App

Now, click Switch to new Dashboard in the bottom-left corner of the screen. In the new UI, open the Paws app once more, then go to App Settings -> Security and Keys.

Locate the following two text strings. You’ll need them later to connect the Paws app to Parse.

  • Application ID
  • Client Key
Parse: App Keys
Parse: App Keys

Next, open the Paws workspace in Xcode and open the AppDelegate.swift file. At the top there’s a couple of configuration code lines. Do this:

  • First, uncomment (remove the //) the first Parse.setApplicationId(... line.
  • Then, replace the first ... with the Application ID you located earlier.
  • Then, replace the second .... with the Client Key you located earlier.
  • Finally, comment the entire let config = ... to ... Parse.initializeWithConfiguration(config); code block. You’ll use it later.

The first part of the code block now looks like this:

Parse.setApplicationId("<your application id>", clientKey: "<your client key>");

Parse.setLogLevel(PFLogLevel.Info);

/*let config = ParseClientConfiguration(block: {  
    (ParseMutableClientConfiguration) -> Void in

    ParseMutableClientConfiguration.applicationId = "...";  
    ParseMutableClientConfiguration.clientKey = "...";  
    ParseMutableClientConfiguration.server = "...";  
});

Parse.initializeWithConfiguration(config);*/

let tableVC:CatsTableViewController = CatsTableViewController(className: "Cat");  
tableVC.title = "Paws";

...

Finally, run the app by pressing Command-R or by clicking on the Run button at the top-left of Xcode. Make sure you’ve selected an iPhone Simulator device, or connected your own iPhone or iPod Touch. The app should compile and run, resulting in a screen similar to this:

Xcode: Running The Paws App
Xcode: Running The Paws App

OK, now imagine the following happens:

  1. You publish the beautiful Paws app on the App Store and amass a large number of monthly active users. You sit back and enjoy your app with its convenient Parse back-end.
  2. Parse announces it’s shutting down its service…
  3. You FREAK OUT! What now? I mean, you had two certainties in your life: Parse and taxes!

Fortunately, the fine folks at Parse transmuted their Platform-as-a-Service in a well-coded Parse Server NodeJS/Express package. You can essentially run the (almost) full Parse service on any webserver that supports MongoDB and NodeJS. Awesome!

2. Creating A MongoDB Database With mLab

OK. We saw in the overview at the top of this article that Parse will now run on two new services: Heroku and mLab. Essentially, Heroku hosts and runs the Parse Server code and mLab hosts the app’s data in a MongoDB database.

Let’s first set up the mLab service. At this point you’ve either recreated the Paws app with the original Parse, or you didn’t have a Parse account but still want to use Parse Server.

Deploying The MongoDB Database

First, make sure you have a mLab account by signing up at mlab.com. Then, log into your new account.

Note: you need to verify your email address before you can create any new deployments. Sign up, wait for the verification email to arrive in your inbox, click the link, then get back to the mLab dashboard.

On the dashboard, click the Create New button. On the page Create new subscription page that appears, do the following:

  • First, choose Amazon Web Services as cloud provider.
  • Then, choose Amazon’s US East (Virginia) Region (us-east–1) as location.
  • Then, select the Single Node tab and choose the Sandbox option. This is mLab’s free tier, which has more than enough capacity for our app.
  • Then, name the database paws.
  • Finally, click Create new MongoDB deployment.

The new database is created. You can of course choose different MongoDB options depending on the requirements of your app. Keep in mind that the original Parse service compressed your app’s data. Parse recommends to 10x the size of your Parse data when creating a new MongoDB database.

If all went OK, you’ll be redirected to your mLab dashboard which shows the newly created database. Click on the database to open its detail screen. Note the mongodb:// URL at the top, we’ll need it later.

mLab: Database details
mLab: Database details

Next, do this:

  • First, click the Users tab.
  • Then, click Add database user.
  • Then, in the dialog that appears, input paws as username and input a strong password, then click Create. Make sure to leave the Make read-only checkbox unticked.

Make sure you note the paws username and its password somewhere safe. You will need it later.

Synchronizing Parse With mLab

You can skip this step if you don’t have a Parse account. Continue with “Importing Data In mLab”.

Copy the mongodb:// URL you located earlier to a text file and replace the <dbuser> and <dbpassword> with the username and password you just created. The result should look something like this:

mongodb://paws:mypassword1234@ds033298.mlab.com:33297/paws

Then, switch back to the Parse Dashboard at https://dashboard.parse.com/ and open your Paws app. Next, go to App Settings -> General and click on the Migrate button (in red).

Then, paste the mongodb:// URL in the input field and click Begin the migration. You’ll be taken to a screen that shows the process of the migration. Parse will now send all your data to mLab, which shouldn’t take long.

Parse Migration
Parse Migration

Note: the migration is essentially complete when the first bar turns green. Parse is still looking for new data that was entered since the migration, but because our Paws app isn’t used in a production environment,no new data is added.

Once all the bars are green, and you’ve had the chance to manually verify the data, Parse will switch to using your self-hosted MongoDB database instead of the Parse hosted database. That’s pretty cool! Parse still takes in requests from your connected app clients (the one’s your users use), but instead of reading and writing to the Parse hosted database, it reads and writes from and to your own self-hosted database on mLab.

OK, that’s it! This concludes the first part of the migration. You can skip ahead to Deploying Parse Server On Heroku.

Learn how to build iOS apps

Get started with iOS 12 and Swift 4

Sign up for our iOS development course Zero to App Store and learn how to build professional iOS 12 apps with Swift 4 and Xcode 10.

Importing Data In mLab

Only complete these steps if you don’t have a Parse account.

OK, you don’t have a Parse account but still wanted to follow this code guide to learn how to deploy Parse Server. You’re essentially creating a fresh new Paws app, but directly deploying it on Heroku and mLab without using the original Parse.

Note: At this point, you need to have the Paws source code set up, have created a mLab account, created the paws MongoDB database, and created the paws database user. Make sure you’re logged into your mLab account and open your dashboard at mlab.com/home.

In order to get the app data into your MongoDB database, you’ll need to import it with a JSON file. To do that, you need to have the MongoDB tools installed on your Mac’s OS X.

Before you can install the tools, you need to install Homebrew. Homebrew is a package manager for OS X and you can use it to install several command-line tools Apple didn’t install by default on OS X. One of those tools is MongoDB.

Note: Read on brew.sh how to install Homebrew.

Once you’ve installed Homebrew, run the following Terminal command to ensure you’ve got the latest version of Homebrew.

$ brew update

Next, install MongoDB with this command:

$ brew install mongodb

Next, run the following command to verify the toolset was installed correctly:

$ mongoimport --help

Next, download the following file: paws_mongodb.zip and unzip it in a convenient location. Make sure the resulting unzipped directory is called paws.

Next, go to your mLab dashboard, open the paws database and click the Tools tab. You’re now on a page that lists a number of CLI commands to work with MongoDB.

Find the first one, right below Import database. It’s similar to:

$ mongorestore -h ds051645.mongolab.com:51645 -d paws -u <user> -p <password> <input db directory>

You have just installed this mongorestore command with Homebrew. The tool restores a MongoDB database, based on parameters, essentially entering data into the empty database you created previously.

Before you can use the command, you need to configure the parameters. It’s easiest if you first copy the entire command from your mLab Tools page to a text file.

Then, edit the parameters one by one:

  • First, replace <user> with paws
  • Second, replace <password> with the password you entered earlier.
  • Third, replace <input db directory> with paws.

The entire command now looks similar to this:

$ mongorestore -h ds051645.mongolab.com:51645 -d paws -u paws -p password1234 paws

Don’t input the command in Terminal just yet. First, use Terminal and cd to navigate to the directory you unzipped the paws_mongodb.zip in. For instance, if you downloaded the ZIP file to your downloads directory at ~/Downloads, do the following:

$ cd ~/Downloads

Once you’ve navigated to the right directory, copy and paste the mongorestore command from the text file into Terminal and press enter. The result in Terminal looks something like this:

Terminal: Restore MongoDB Database
Terminal: Restore MongoDB Database

As you can see, I’ve unzipped the ZIP in ~/Downloads as subdirectory paws and restore that database to a MongoDB called paws-test with username paws and password abcd1234.

Verify that the data import went OK by checking your MongoDB’s collections with the Collections tab in the dashboard.

mLab: Collections OK!
mLab: Collections OK!

Alright! That’s it for migrating to MongoDB. Because the steps involved are quite complex, this is a high-level recap:

  1. Get a mLab account and log in.
  2. Create a paws MongoDB database (free tier on AWS, US East)
  3. Create a paws user, note the password somewhere.
  4. If you have a Parse account and want to migrate the app’s data:
    • Note the MongoDB URI
    • Replace the <dbuser> and <dbpassword> with the right values.
    • Go to Parse, choose Migrate, input the URI and start the migration.
    • When it completes, verify the data and complete the migration.
  5. If you don’t have a Parse account and want to start a fresh app with Parse Server:
    • Install Homebrew, the MongoDB command-line tools, and verify mongorestore works OK.
    • Go to the Tools tab of your database in mLab.
    • Note the Import database CLI command, copy it to a text file, and change its parameters to reflect your values (username, password and directory).
    • Use Terminal and cd to navigate to the right directory (~/Downloads if you unzipped the ZIP data file in that directory.)
    • Paste the mongorestore command from the text file in Terminal and execute the command.
  6. Finish!

Note: Remember that you can get your MongoDB URI from your mLab dashboard, you’ll need it later.

3. Deploying Parse Server On Heroku

OK. Now that the MongoDB database is set up to contain your app’s data, we need something that hosts and executes the Parse Server code.

Parse Server, the roll-your-own-Parse package, is a NodeJS Express application. That means you can run it on any server that’s capable of running NodeJS, such as an Amazon Web Services instance, a Digital Ocean or Linode VPS, and even Microsoft’s Azure. In this code we’ll be using Heroku.

Heroku is a Platform-as-a-Service, just like Parse, AWS, Digital Ocean, etc. You read in the overview that Parse is a done-for-you, managed and scalable Platform-as-a-Service.

If you would draw a line, put Parse on the right, and a bare-metal (or VPS) server on the left, you can place Heroku somewhere in the middle. You don’t have to manage your own virtual servers, but you still have to manage your own app instances. Parse did that all for you, which meant you essentially didn’t have to worry about scaling your back-end anymore.

With Heroku you create containerized instances of your app. One container for every Parse Server app. You’ll connect the app with your MongoDB database, through a configuration parameter which you’ll set to that MongoDB URI you noted earlier.

Let’s get started!

Installing The Heroku Toolbelt

Just like with MongoDB, much of the configuration of Heroku is done on the command-line. Before you have access to these CLI tools, you need to install them.

In order to install, do this:

  • First, go to toolbelt.heroku.com.
  • Then, download the Toolbelt for Mac OS X (or other operating systems, if applicable).
  • Then, once the download finishes, open the PKG file and follow the installation instructions.
  • Finally, to verify the installation is complete, type into Terminal the command $ heroku --help. If you’re seeing the CLI command options, all is OK.

Getting The Parse Server Example Sourcecode

In this code guide we’ll be working with the Parse Server example project. You can find it on GitHub: https://github.com/ParsePlatform/parse-server-example.

You now need to download the source code on your local computer. Do this:

  • First, open Terminal and cd to your home directory: $ cd ~.
  • Then, create a new directory called heroku with $ mkdir heroku.
  • Then, cd into the new directory with $ cd heroku.
  • Then, clone the parse-server-example with Git in the current directory. You do that by typing: $ git clone https://github.com/ParsePlatform/parse-server-example.git. Git will now download the source code and put it in a new directory called parse-server-example.
Terminal: Cloning Parse Server Example Sourcecode
Terminal: Cloning Parse Server Example Sourcecode

Setting The Parse Application ID And Client Key

Before the Paws iOS app can communicate with the Parse Server we’re setting up, it needs to authenticate itself with Parse Server. Authentication works sort of like a password and in our case, the password consists of an Application ID token and a Client Key token.

Previously, Parse generated and kept these two tokens (random strings of text), but with Parse Server you need to set them yourself.

In order to do that, open the file index.js in the ~/heroku/parse-server-example directory with your favorite text editor. Use Finder to navigate to your home directory, then open the directory called heroku, then open parse-server-example, then open the index.js file.

Locate the JavaScript code line that starts with var api = new ParseServer({ ....

Setting The Parse Application ID And Client Key
Setting The Parse Application ID And Client Key

With this code block, a new Parse Server is created with a number of configuration parameters. For instance, the databaseURI is set according to the environment variable we’ll set later in Heroku, DATABASE_URI. Also, the appId and masterKey are being set.

At this point you need to generate three text strings of random characters. You can do that in two ways:

  1. Copying the tokens from your Parse Dashboard:
    • First, open your Parse Dashboard and go to your app, then go to App Settings -> Security And Keys.
    • Then, Locate the three keys: Application ID, Client Key and Master Key (bottom, need to click Show Master Key first).
  2. If you don’t have Parse, generate three new tokens with random.org:
    • First, go to https://www.random.org/strings/.
    • Then, set the strings to be 20 characters long and tick all the boxes for Numeric, Uppercase and Lowercase characters. Set the strings to be unique, then click Get strings.
    • Then, pick three of the 10 random strings you just generated.

If all went OK, you now have three random text strings. With the strings, do the following:

  • First, get back to that index.js file in your text editor and locate the right code block again.
  • Then, replace myAppId with one of the random text strings. Make sure you type the string between single quotes.
  • Then, replace myMasterKey with one of the random text strings. Also between single quotes.
  • Then, type a comma , at the end of the line that says masterKey.
  • Then, put a newline after that comma, and type this: clientKey: '<random text string>'. Instead of <random text string>, type the third and last random text string you got earlier. (You’ve essentially appended one key-value item to the configuration dictionary.)
  • That’s it!

The entire code block now looks similar to this:

var api = new ParseServer({  
    databaseURI: process.env.DATABASE_URI || 'mongodb://localhost:27017/dev',  
    cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',  
    appId: '<random text string>',  
    masterKey: '<random text string>',  
    clientKey: '<random text string>'  
});

Awesome! You’ve readied the Parse Server code locally. Now let’s get it to Heroku.

Setting Up Heroku

Alright, at this point you need a Heroku account. Go to heroku.com and sign up for an account. Note your account username and password somewhere safe.

Note: You need to verify your account email address before you can use Heroku. Sign up, wait for the verification email to arrive, click the link, then sign back in to Heroku.

Heroku
Heroku

Next up, make sure the Heroku Toolbelt knows who you are. Type the following in Terminal:

$ heroku login

When Heroku asks for it, input your username and password.

Next, we’re going to deploy the local code of Parse Server to a Heroku instance. It’s incredibly easy…

First, make sure you’re still in the ~/heroku/parse-server-example directory with Terminal (or the directory where you cloned your Parse Server example code).

Then, type this on the command line:

$ heroku create

Heroku will now create an app for you, assign it a random name and add a Git “remote” to the repository. This is one of the powers of Heroku: you can deploy and update your app’s code with Git.

The output at the command line will be similar to this:

~/heroku/parse-server-example $ heroku create  
Creating app... done, stack is cedar-14  
https://vast-shelf-54389.herokuapp.com/ | https://git.heroku.com/vast-shelf-54389.git

Next up, you need to add the recent code changes (for the App ID and Keys) to your local repository. You changed the file, indeed, but these changes also need to be tracked in the Git repository. Input the following two commands in Terminal.

$ git add index.js  
$ git commit -m "Changed configuration values"

The index.js file is now added to the local repository, but the source code change is not uploaded to the Heroku instance we created. We’ll do this now. You’ll upload your Parse Server example code (called pushing) to the Heroku instance you created with heroku create. Heroku will then deploy the code for you on the Heroku instance.

Type this in Terminal:

$ git push heroku master

If all goes OK, you’ll see a bunch of lines racing across your screen. If you dig a little deeper, you’ll see Heroku recognizes the NodeJS app, builds a whole bunch of dependencies (library code Parse Server uses), and then attempts to restart the app process (which doesn’t exist).

At this time, the Parse Server code now resides with Heroku, but our Parse Server app hasn’t started yet!

Next up, we need to set that environment variable that points to your MongoDB database instance. You’ll do that with the MongoDB URI. You can find it at the top of your mLab dashboard:

Heroku Dashboard: mLab URI
Heroku Dashboard: mLab URI

Copy your mLab URI to a text file and then replace <dbuser> and <dbpassword> with your own username paws and password.

Note: Don’t use your account username and password, but use the username and password you created for the paws database. If you followed this guide, the username should be paws and the password something you set.

Next, type in the following in Terminal on the command line (still in the same directory). Replace the mongodb://... part with your own MongoDB URI.

heroku config:set DATABASE_URI=mongodb://...

The entire command should look similar to this:

heroku config:set DATABASE_URI=mongodb://<dbuser>:<dbpassword>@ds051647.mongolab.com:51647/paws

You can verify the environment variable was set correctly by going to your Heroku Dashboard, clicking on the name of your instance (mine’s called powerful-dawn) and then clicking on the Settings tab. Then, click on Reveal Config Vars. If you’ve set the DATABASE_URI right, it should show up.

Config Vars
Config Vars

Alright, we’re almost there. Next up: starting the Heroku instance! In order to start the Heroku instance, type this on the command-line, still in the same directory:

heroku ps:scale web=1

And then:

heroku open

The first line starts a process for the Heroku app, and the second line opens your browser and shows the response from the Heroku app. If all went OK, it should say:

I dream of being a web site.

Awesome! Your Heroku instance is now complete.

Note: Normally, you’d manage your app’s processes with a Procfile. Also, you can see that “I dream of …” line show up in the file index.js. By the way, looking at the source code of parse-server-example you can’t help but notice it’s very small… Where’s all the source code? It’s in a dependency, the library is called parse-server and you can find it’s code at: https://github.com/ParsePlatform/parse-server.

4. Configuring The “Paws” App

Yessss, no more command line! Next up, we’re going to connect the Paws iOS app with the new Heroku web service – your own Parse Server instance!

Start the Paws.xcworkspace in Xcode and open the AppDelegate.swift file. You’ve worked with this file before. Then, do this:

  • First, comment (or remove) the first code line of the method application:didFinishLaunchingWithOptions: by placing // at the beginning of the line.
  • Then, uncomment the comment block you created earlier a couple of lines down around the let config ... block.
  • Then, replace the ... for applicationId and clientKey with their respective values. You can find those values in index.js of parse-example-server, if you forgot them. You don’t have to set masterKey.
  • Finally, copy the URL of the web page that said I dream of being a web site.. It looks like this: https://[app instance name].herokuapp.com. Paste it for the server configuration in AppDelegate.swift. Make sure you type /parse at the end of the URL!

Make sure you’ve got the Swift syntax right (no spaces, single quotes) and double check you’ve correctly copied and pasted the configuration values. Check out the following screenshot if didn’t get it right.

Xcode: New Configuration
Xcode: New Configuration

Next up, the piece de resistance, let’s see if it actually worked! Run the app with Command-R on iPhone Simulator or your own device. It’ll probably take 5–6 seconds before you’re seeing cat pictures after the app starts, but if all went OK you should see them.

Didn’t work? Bummer! Ask for help in the comments.

Did it work? AWESOME! YOU ROCK!

Aw yisss... cat pictures!
Aw yisss… cat pictures!

But… the result is the same as when you’d use the original Parse, right? I mean, that’s the point, but how can you make sure the app uses the right back-end?

OK, testing that is easy. Note down the number of votes the first image has, and what the name of the cat is. For instance, Azrael and 6 votes.

Then, double tap the cat picture. A cat paw should pop up (cute!) and the vote count should increase to 7 votes.

Then, open your mLab Dashboard and click the Connections tab for your MongoDB database.

Then, click the Cat collection. A rudimentary overview of the cat data should show up. In the list, find the Azrael cat (you can use Command-F). Locate the votes key for the item and check what the vote count is. Is it 7? Awesome, it works!

Check The Data
Check The Data

Conclusion

Pfew… that was quite some work! Did it all work out? Well done. You’ve just successfully migrated from Parse to Parse Server on Heroku and mLab!

Did you like this coding guide? Make sure to check out the Pro Course, a solid online course that shows you how you can build and market your own apps.

What’s next? Now you actually have to worry about indices, database size, and scaling up your back-end. Another day, perhaps…

Parse has been a landmark for a large amount of app makers around the world and it will be missed. I reckon the migration is an education for many app makers, because it forces them to start thinking about back-end portability and reliability, while at the same time making them experience what it’s like to run your own back-end.

You could argue about the effect of acquisitions of the Internet Big Five (Amazon, Google, Facebook, Microsoft and Apple) of small high-tech companies on the internet and app ecosystem as a whole. The “for app makers, by app makers” seems to fade quickly in the face of multi-million dollar acquisitions. Facebook is focusing on mobile advertisement and the next big thing: virtual reality, and left an in 2013 risky acquisition (almost) for dead.

Perhaps now a decade starts in which the authentic Platform-as-a-Service underdog will remain in competition with the Big Five, instead of being incorporated by it.

I remember trying to get a spare Pentium II to run a web service 15 years ago. A lot has changed since then, especially the speed of change. With one thought, I’m a big fan of done-for-you services because they aid rapid prototyping. On another thought, I’m also a fan of tinkering and showing my peers how to tinker with technology. Maybe we got a little lazy, because the tools we relied on got too easy to use.

Your contingency for a change in technology, and its reliability, is to never unlearn how to tinker.

Learn how to build iOS apps

Get started with iOS 12 and Swift 4

Sign up for our iOS development course Zero to App Store and learn how to build professional iOS 12 apps with Swift 4 and Xcode 10.

Further Reading

There’s much more to find out!

Reinder de Vries

Reinder de Vries

Reinder de Vries is a professional iOS developer. He teaches app developers how to build their own apps at LearnAppMaking.com. Since 2009 he has developed a few dozen apps for iOS, worked for global brands and lead development at several startups. When he’s not coding, he enjoys strong espresso and traveling.