Parse Server on Simple Hosting Node.js

Parse Server is the free software version of Facebook's Parse service. This tutorial will show you how to easily deploy your own Parse Server on Simple Hosting.

You'll need git and ssh installed on your computer to complete this tutorial.

We also recommend that you use Gandi CLI to easily manage your instance and execute commands directly from the command line.

Step 1 - Create your Simple Hosting instance

Using Gandi CLI :

  $ gandi paas create --name myparse --type nodejsmongodb

You'll need to have enough money on your prepaid account to complete this step, otherwise you can go to the website to conclude the purchase.

Through Gandi's website :

https://www.gandi.net/hosting/simple?language=nodejs&db=mongodb

Once your instance is created, note the default VHOST (test URL) that was created for you.

With Gandi CLI, you can retrieve it like this:

  $ gandi paas info myparse | grep vhost

On the website, you'll find the test URL on your instance's management page.

Step 2 - Prepare your Parse Server

Parse Server provides an example project that we'll use in this tutorial.

Clone the project's repository onto your computer to get started :

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

Enter the directory you have just cloned and create an .nvmrc file, that you'll use to specify which version of Node.js you want to run on Simple Hosting. In this case, it's Node.js 4.3.

  $ cd parse-server-example
  $ echo "4.3" > .nvmrc

Then, modify the package.json file to define the environment variables for your Parse server instance in your start script definition:

  "scripts": {
    "start": "APP_ID=theAppId MASTER_KEY=s0m3th1ngth4t1sh4rdt0gu3ss SERVER_URL=http://<randomstring>.test-url.ws/parse node index.js"
  },

Now, add and commit the .nvmrc and package.json file to your git tree.

  $ git add .nvmrc package.json
  $ git commit -m "Specify Node version and environment variables"

Step 3 - Deploy to your instance

Start by adding a git remote location to attach your local git repository to the one on your Simple Hosting instance.

Then deploy your code in two steps: perform a git push to your remote repository, then execute the deploy command over ssh to build your project and place it on your instance.

You'll just have to repeat these last two steps anytime you want to deploy changes to your app.

Using Gandi CLI:

  $ gandi paas attach myparse
  $ git push gandi master
  $ gandi deploy

Using plain git and ssh :

  $ git remote add gandi git+ssh://{id}@git.{dcX}.gpaas.net/default.git
  $ git push gandi master
  $ ssh {id}@git.{dcX}.gpaas.net 'deploy default.git'

Replace the {placeholder} values in the example above with the ones you'll find on your instance's admin page.

Step 4 - Testing your Parse Server

Your Parse Server is now up and running on Simple Hosting and you can access its API endpoint at {randomstring}.test-url.ws/parse.

To test it from your Terminal with CURL, you can use :

  
  $ curl -X POST \
    -H "X-Parse-Application-Id: theAppId" \
    -H "Content-Type: application/json" \
    -d '{"hello":"world"}' \
    http://{randomstring}.test-url.ws/parse/classes/Test
  

Step 5 - Real world usage

Integrating with mobile or web applications

Your Parse server can be used like any Parse server.

There is extensive documentation on ” How to migrate from the hosted Stripe service to your self-hosted instance”. It will tell you how to adapt your existing code to start using your new Simple Hosting instance instead of the deprecated service.

There are also good examples on how to use Parse's SDKs for web and mobile platforms if you're creating a new application. We recommend you check those out, as they largely apply to your usage on Simple Hosting.

Using your own domain

You can add a VHOST to your instance to make your Parse server accessible on your own domain.

With Gandi CLI:

  $ gandi vhost create www.example.com --paas myparse

From Gandi's website, you can add the VHOST on the instance management page.

Then modify the SERVER_URL environment variable in your start script definition, in the package.json file.

  "scripts": {
    "start": "APP_ID=theAppId MASTER_KEY=s0m3th1ngth4t1sh4rdt0gu3ss SERVER_URL=http://www.example.com/parse node index.js"
  },

Commit your changes and redeploy your application to make the change effective.

Using your own domain with SSL

To enable SSL, you'll need to have at least an M-size instance and activate SSL on the instance and VHOST.

  $ gandi paas update myparse --size m --ssl

If you want to create a certificate, generate a private key on your computer and use the following command to create the VHOST:

  $ gandi vhost update www.example.com --ssl --pk /path/to/your/key --poll-cert

If you already own a certificate, simply add it to the Cert Store, then activate SSL on the VHOST:

  $ gandi certstore create --pk /path/to/your/key --crt /path/to/your/certificate
  $ gandi vhost update www.example.com --ssl

Then modify the SERVER_URL environment variable within your start script definition, in the package.json file.

  "scripts": { 
    "start": "APP_ID=theAppId MASTER_KEY=s0m3th1ngth4t1sh4rdt0gu3ss SERVER_URL=https://www.example.com/parse node index.js"
  },

Commit, push and deploy your changes like before and your Parse server will be secure!

Last modified: 04/06/2016 at 13:09 by Alexandre L. (Gandi)