|||

Video Transcript

X

Announcing Heroku + Parse: Flexible Platform Meets Feature-Rich SDKs

Most modern mobile apps depend heavily on the app’s back-end. That’s because many of the expectations users have for mobile apps today -- for the application to work regardless of network connectivity, to notify them when relevant content changes, to have integrations with the social networks they use, for appropriate levels of security, and a hundred other things -- are reliant on the app’s back-end services.

The most common pattern for mobile back-ends we see today is for developers to design, build and maintain their back-end architectures on Heroku. This approach is as flexible as it is powerful, but it requires significant engineering effort. A faster alternative would be to use a service like Parse. Using the Parse SDKs gets you some great services right out of the box. However, if you need to add customized functionality to your application at scale, there just isn't a simple way to do it.

We’re pleased to announce the first results of a partnership between Heroku and Parse aimed at delivering the best of both worlds. Today we’re making available an integration between Heroku and Parse’s Cloud Code product. This combination gives you the flexibility and customization of the Heroku platform and the convenience of Parse’s cross-platform mobile SDKs. This is just the beginning, and as we continue to work together on extending and improving the integration, we welcome your feedback.

Watch this screencast for a 3-minute overview of how this works, and then read on to see how you can begin using Heroku and Parse together today.

How this works

To begin taking advantage of the integration, you'll need a Parse account, a Heroku account and the respective CLI tools.

Let's start by using the Parse command line tool to provision a new Parse app.

$ parse new

We'll be prompted to choose an existing Parse app, or to create a new one and name it. Let's create a new one:

Would you like to create a new app, or add Cloud Code to an existing app?
Type "(n)ew" or "(e)xisting": n

Next, we select Heroku as our provider:

Which of these providers would you like use for running your server code:
  1) Heroku (https://www.heroku.com)
  2) Parse  (https://parse.com/docs/cloudcode/guide)
       Type 1 or 2 to make a selection: 1

Note: If your Heroku account isn't linked to your Parse account, it's at this point that you'll be directed to the appropriate settings page.

The Parse CLI will finish by generating the Node Express scaffolding. Now we can cd into our new project directory, and deploy it to Heroku:

$ cd Parsoku/
$ parse deploy

That's it; you have the full power of Heroku’s developer experience, combined with the convenience of Parse’s cross-platform mobile SDKs at your disposal.

Taking it up a level

We've provisioned new Parse and Heroku apps, generated an Express server, and deployed it to Heroku. Not a bad start, but we're not finished yet. The Heroku add-ons ecosystem includes a wide selection of services that we can use to add functionality to our Express server. Let's use the SendGrid add-on to welcome new users.

Note: Parse does not add a User class by default. Add the User class via the Parse dashboard before continuing.

First we'll provision the add-on:

$ heroku addons:create sendgrid -a parsoku-app-name

Which made our SendGrid credentials available to our app via config vars, you can inspect those using the Heroku toolbelt:

$ heroku config -a parsoku-app-name

We'll also need to install the SendGrid library:

$ npm install sendgrid --save

With our SendGrid add-on ready to go, we can use the config var added through the provisioning process in tandem with the library we installed to send a welcome message each time a user signs up.

It's time to customize the Express server:

// /cloud/main.js

var Parse = require('parse-cloud-express').Parse;
var sendgrid = require('sendgrid')(process.env.SENDGRID_USERNAME, process.env.SENDGRID_PASSWORD)

function sendWelcome(email) {
  var opts = {
    to: email,
    from: 'creager@heroku.com',
    subject: 'Welcome to webscale mobile apps',
    text: 'Welcome, and thanks for signing up!'
  }

  sendgrid.send(opts, function(err) {
    if (err) {
      console.error('unable to send via sendgrid: ', err.message);
      return;
    }

    console.info('sent to sendgrid for delivery')
  })
}

Parse.Cloud.afterSave('_User', function(request, response) {
  if (request.body.object.email) {
    sendWelcome(request.body.object.email);
  }

  response.success();
});

Now we add and commit the changes we've made via git:

$ git add cloud/main.js package.json
$ git commit -m "Welcome new users"

Finally, we're ready to deploy the latest version of our Express server:

$ parse deploy

You can test that it's working by visiting the Parse dashboard and manually adding a user. Use either the Heroku toolbelt or Parse command line tool to peek under the hood: $ parse logs -f

We can't wait to see what you build with this integration, as always we welcome your feedback, issues and of course PRs. Parse CLI is open source, and available on GitHub.

Originally published: October 22, 2015

Browse the archives for news or all blogs Subscribe to the RSS feed for news or all blogs.