Using Parse and Express

George Markham
Jul 22, 2017 · 2 min read

In my last post I showed you how to setup Parse-Server in order to get data to an iOS app written in Swift 3. In this post we’re going to dive a bit deeper and setup our own Parse-Server application using Express in NodeJS. By doing this you can gain a lot more control over your Parse-Server backend. Most interestingly it enables you to setup live queries to create realtime applications which is what we’ll be building towards.

NOTE: I am assuming you have NodeJS installed and have at least got a bit of experience with it, if not then check it out, it’s awesome.

Firstly create a new directory called whatever you want and cd into it in terminal, create a file called index.js, next run npm init

Follow the prompts and when it exits your NodeJS application is ready to go. Next we’ll need to install the Express and Parse modules, type npm install --save express parse-server.

This will install the modules to your project and save them as dependencies in your package.json file, this means that if you want to move your project to a different system the modules can be installed by simply running npm install

Once everything is installed go into your index.json file and set up your modules like so:

var express = require(‘express’);var ParseServer = require(‘parse-server’).ParseServer;var app = express();

Next we need to create our actual server object. Create a variable called api and set it to new ParseServer. It should look like this:

var api = new ParseServer({});

We’re going to fill that ParseServer object with all of the credentials for our server, it should look something like this, except your’s should be filled out with your app’s info:

var api = new ParseServer({    databaseURI: ‘mongodb://localhost:27017/DATABASE_NAME’,    cloud: ‘./cloud/main.js’,    appId: ‘APPLICATION_ID’,    masterKey: ‘MASTER_KEY’,    serverURL: ‘http://localhost:1337/parse',});

The cloud bit is where you put the directory for your cloud code, you ought to create that with the main.js file because it may come in useful in the future.

Once that is done you’ll need to connect your Parse-Server to your app we’ll do this by writing:

app.use(‘/parse’, api);

This connects our api variable(Parse-Server) to our application on the ‘/parse’ endpoint, meaning that any traffic going to that endpoint will be handled by Parse.

Next is to get our server to listen out for connections, this is done by writing:

app.listen(1337, function(){    console.log(“Parse-Server running”)})

Quick note about the above code: the callback function isn’t necessary, if you don’t need to do anything when the server starts listening for connections then no need to include it, in saying that it is nice to have a bit of output telling you everything’s working.

And that’s it for Parse-Server, you can connect it up to parse-dashboard and use it as you did last time, it should work exactly the same.

Next post I’ll be using this server to setup live queries in order to create realtime applications.

Thanks for reading!

Software Engineer, currently studying Computer Science at Uni Of Lincoln

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade