Advanced Guides

How to setup a local Parse Server

Introduction

The Development Environment can make it easier to develop, test, debug and deploy code, reducing the amount of time spent on the processes and increasing productivity.

In this tutorial we will show you how to set up a very efficient stack that will allow you to develop and debug locally and, later on, deploy your code to Back4app.

Prerequisites

To begin with this tutorial, you will need:

Step 1 - Choosing a IDE

The IDE (Integrated Development Environment) is a piece of software that offers copmrehensive facilities to programmers, allowing them to produce code easier and faster.

Usually good IDEs offer a few basic features such as syntax highlighting, code completion, refactoring, version control, debugging, code search among others.

There are many free and paid IDEs available so you should probably test a few to see which fits your style best.

Some support only one programming language, while others support multiple. Some are optimized for beginners while others focus on experts.

You can find a list of very good IDEs in Wikipedia but I will leave a link for the most used ones here:

Step 2 - Installing the CLI

The CLI (Command Line Interface) facilitates the process of creating Apps, deploying code, retrieving logs among other useful tasks. Having it installed will help a lot with productivity and task automation.

If you don’t have it installed yet, we heve a full tutorial here.

Once installed, you can run it by typing in your Terminal window

1
b4a

and deploy new code to Back4app is as easy as typing

1
b4a deploy

Step 3 - Running Parse locally

While simple Apps can be directly deployed to Back4app, when dealing more complex applications with lots of Cloud Code that must be debugged quickly, running Parse locally can greatly improve the developing experience and, once the code is fully working, you can deliver that code to Back4app.

The easiest way to install Parse locally is using NPM.

With NPM installed, you can just install Parse and MongoDB globally by running

1
npm install -g parse-server mongodb-runner

Once installed, you can run it locally by typing the command below, changing the APPLICATION_ID, CLIENT_KEY and MASTER_KEY for the values retrieved from Back4app’s Server Settings sections, and /path/to/your/cloud/code/folder/main.js to your local Cloud Code directory:

1
parse-server --appId APPLICATION_ID --clientKey CLIENT_KEY --masterKey MASTER_KEY --databaseURI mongodb://localhost/my-app --cloud /path/to/your/cloud/code/folder/main.js

Step 4 - Installing the Dashboard

While not mandatory, the Parse Dashboard will improve the developing experience by adding a layer of graphical tools to operate your App.

In order to install it using NPM, run the following command in your Terminal:

1
npm install -g parse-dashboard

Once installed, you can run it with the command below, changing the APPLICATION_ID, CLIENT_KEY and MASTER_KEY for the values retrieved from Back4app’s Server Settings, and the MY_APP parameter for the name of your App:

1
parse-dashboard --dev --appId APPLICATION_ID --clientKey CLIENT_KEY --masterKey MASTER_KEY --serverURL http://localhost:1337/parse --appName MY_APP

Step 5 - Changing the Server URL

The main Server URL to connect to Parse in Back4app is https://parseapi.back4app.com , but you should change it in your code to connect to your local Parse instance.

If you followed the steps above, your Parse instance is running in http://localhost:1337/parse, so change your Server URL to reflect that:

Javascript:

1
2
Parse.initialize("YOUR_APP_ID", "YOUR_JAVASCRIPT_KEY");
Parse.serverURL = 'http://localhost:1337/parse'

Java:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import com.parse.Parse;
import android.app.Application;

public class App extends Application {
  @Override
  public void onCreate() {
    super.onCreate();
    Parse.initialize(new Parse.Configuration.Builder(this)
      .applicationId("YOUR_APP_ID")
      // if defined
      .clientKey("YOUR_CLIENT_KEY")
      .server("http://localhost:1337/parse/")
      .build()
    );
  }
}

Swift:

1
2
3
4
5
6
7
8
9
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        let parseConfig = ParseClientConfiguration {
            $0.applicationId = "YOUR_APP_ID"
            $0.clientKey = "YOUR_CLIENT_KEY"
            $0.server = "http://localhost:1337/parse/"
        }
        Parse.initialize(with: parseConfig)
        return true
}

PHP:

1
2
ParseClient::initialize( "YOUR_APP_ID", "YOUR_CLIENT_KEY", "YOUR_MASTER_KEY" );
ParseClient::setServerURL('http://localhost:1337','parse');

.Net:

1
2
3
4
5
6
7
using Parse;
ParseClient.Initialize(new ParseClient.Configuration
{
    ApplicationID = "YOUR_APP_ID",
    Key = "YOUR_CLIENT_KEY",
    ServerURI = "http://localhost:1337/parse/"
});