Following Parse’s announcement of the service winding down and the subsequent release of the Parse API Server, I’ve taken the time to setup my own instance of the open-source software to help migrate from Parse.com before it shuts down in January 2017.
Prerequisites
If you’re setting up Parse Server on your server or local machine, you need to make sure the following packages are installed:
- NodeJS v4.1+ (tested with v4.2.6)
- MongoDB version v2.6.x or v3.0.x (tested with v3.0.9)
- Python 2.x (tested with v2.7.6)
Setting up Node Modules
Decide on where you want your Parse API server to live on your server. For the purpose of this guide, I’m using the location /var/www/parse/
. Start by installing the following Node packages using npm
:
Note: If you have trouble installing the above packages, you may need to make sure you have the required dependencies installed. For example, installing the libkrb5-dev
library, using the following command line on Ubuntu:
sudo apt-get install libkrb5-dev
Setting up Parse Server
Once the packages are installed, we create a Express App to mount the Parse API at a specified path. I created the file app.js
within the /var/www/parse/
folder (this folder should now contain a folder called node_modules
) and copied and pasted in the below code:
You will need to change the databaseURI
setting (line 9) to point to your MongoDB instance.
Remember to change the appId
and masterKey
settings (line 10-11) in the above file to reflect your application. If you want to use a different path or port, you can change those too in the above code. By default, the API will be served on the /parse
URL (e.g. https://localhost/parse
), using port 1377
.
Running the Parse Server
Once everything has been setup, you can start the Parse API server by running node app.js
from the installed folder. If everything works correctly, you’ll see something like:
Then, if you visit your server URL, e.g. https://localhost:1377/parse, you should see the Parse API server running:
I know what you’re thinking… It may look like an error message, but it means the Parse API server is working. Now you can confirm it by following the verification steps below.
Verification
You can also verify that the Parse API Server is running correctly by using some cURL commands. For example, you can issue the following two commands to save and retrieve data:
Amazom AMI
I have also created a Amazon Machine Image (AMI) on AWS with everything already setup and ready to go. You can follow this AWS Guide to add my AMI.
The AMI Name is: Parse-Server
(located in Europe Ireland)
Bugs and Issues
The Parse API Server was only recently released and may not work exactly as the Parse.com service works. If you encounter issues with using the server, you can post your issues and bugs on the Issue Tracker.
For anything else, feel free to post a comment below.
[…] you are looking to install the Parse API Server on your Ubuntu machine, make sure you install […]
Thanks to the tutorial, Coulnd find the AMI Name: Parse-Server.
Sorry, I forgot to mention that AMI is located in Europe Ireland, but you can then copy to any region.
I got the same unauthorized error..does that mean it is running though?!
Yep, if you’re seeing
{"error":"unauthorized"}
when visiting the API via a browser, it means its working. If you call it using your API Key or the verification code I’ve posted, it will return success / failure as the Parse API does.Hi Niraj, Thank you for your reply. Really Really appreciate it. I am so devastated because I have zero knowledge about node.js and mongo db. After a few hours of studying, I got some basic concepts now.
However, from my understanding, the following code in index.js will write that log when visiting “localhost/parse”? Please advice me if I am wrong.
var port = process.env.PORT || 1337;
app.listen(port, function() {
console.log(‘parse-server-example running on port ‘ + port + ‘.’);
});
In addition, when running parse server, I got the following saying DATABASE_URI not specified but I did provide it to my local mongo URI (databaseURI: ‘mongodb://localhost:27017/dev’)? Again, Probably I am wrong. Please share your thoughts on this!! Many thanks in advance.
> node index.js
DATABASE_URI not specified, falling back to localhost.
parse-server-example running on port 1337.
The code you’re referring to will print to the console when you run the script, not when visiting the URL. My tutorial has a screenshot you what you’ll see when visiting the web page, and when running the script.
Did you use the code from my tutorial to setup the script, or did you use another source? The error suggest that the parameter is not correctly set.
@Niraj Shah, I deployed the AMI but Im having problems when I try to run the Parse server with node app.js. This is the error on the terminal::::
ubuntu@ip-172-31-30-19:~$ node app.js
module.js:328
throw err;
^
Error: Cannot find module ‘/home/ubuntu/app.js’
at Function.Module._resolveFilename (module.js:326:15)
at Function.Module._load (module.js:277:25)
at Function.Module.runMain (module.js:442:10)
at startup (node.js:136:18)
at node.js:966:3
ubuntu@ip-172-31-30-19:~$
What should I do?
Thanks
@Niraj Shah, never mind, forgot access the path: /var/www/parse/
Glad you got it working. You are free to move the
app.js
file and thenode_modules
folder to any location you want, it will still work.[…] If you’re running the default Ubuntu 14 LTS server on AWS, you’ll find that the package manage will only install MongoDB v2.x. However, you can install the latest version by updating apt-get using this tutorial, allowing you to use install the Parse API Server. […]
@Niraj Shah, thanks for your support men. How do I test the deploy using AWS. Me as @dp have zero knowledge of working under this environments. How do I test the severs if I have everything running on AWS with the AMI?
Follow the verification setups in my tutorial to test your AWS setup. Instead of using the
localhost
inhttp://localhost:1337/parse
, use the IP address of your AWS server so you can access it from your PC, e.g.http://your_aws_ip}:1337/parse
. As long as you are running the script using the commandnode app.js
, the server is working.You can also visit:
http://{your_aws_ip}:1337/parse
in a browser to test that it works (replacing{your_aws_ip}
with your server IP address).Thats, exactly what I did last night, but did not work… I wont if I have todo any other install on the AMI instance.
You need to give me more details about what doesn’t exactly work? Do you get a error message? does the page fail to load? Post the error message or share a screenshot of what you see. AWS Instances are protected my firewalls by default, so you may need to open up access to port 1337 (or all ports if its easier). See the AWS EC2 Help Section to learn how to edit the firewall settings.
Hello, I followed this post, I think is everything is running, but when I try access http://52.27.220.189:1337/myparse I got ERR_CONNECTION_TIMED_OUT.
Do you know what I can do to fix this?
Have you opened up port 1337 on your firewall? By default it’s blocked, so you’ll need to allow access.
Thanks for this Niraj, I think that I have the AMI installed, I have the security groups set for port 80 and safari is saying that it can’t connect to the server. via ssh I followed the rest of your guide and it says that Parse Server is running on port 1377. Also, how do I find the mongoldb URI if I installed your AMI? If you have any input on these id appreciate the help.
Ok, I have the Server showing that “error” in the browser. Forgive me, as I like others that were using Parse know little to nothing about this backend stuff. while using ssh and typing node app.js it starts the purse server and I am able to get that error message. the command line doesn’t allow me to enter any commands at this point. and if I ctrl-c to get a prompt back then I can’t get the error message anymore. So how do I enter the curl commands that you are referencing in your post to test the server?
OK, the error message means it’s working. To run the cURL commands, you should use a second terminal window to input these in. Using Ctrl-C on the window running the app will always shutdown the Parse server. What I do is use 2 terminal windows: (1) to run the Parse Server, (2) to run the cURL command lines or access MongoDB to verify data has been correctly saved.
You also need to make sure port 1337 is allowed via the firewall too. The script I’ve created on the AMI already has the correct MongoDB URL set:
mongodb://localhost:27017/myapp
. You just need to change themyapp
part to reflect the name of your app.Ive made lots of progress thanks to this post and AMI. One more question would be updating. How do I go about updating this parse server to the most recent version of parse server?
From the
/var/www/parse
directory, you can runnpm update parse-server
to update to the latest version of Parse Server. Pretty easy!How do i access cloud code ?
i tried using following curl
curl -X POST
-H “X-Parse-Application-Id: appid”
-H “Content-Type: application/json”
-d ‘{}’
localhost:1377/parse/functions/hello
but got error {“code”:141,”error”:”Invalid function.”}.
Please help
Before you can use Cloud Code, you’ll need to update the
ParseServer
setup inapp.js
. Add a line like:And remember to change the path to match the exact location. Then, the command you used above should work.
Thank you,it is working now.
Thanks @Niraj Shah.
One question i have is if i update contents of main.js that do not gets reflected untill i restart the server,but on Parse.com there was no such need to do it.
How this can be automated?
Parse.com probably did restart your app when your cloud code was updated, but it was likely hidden from the user. Depending on how you deploy the code to the server, you can most likely setup a hook to detect changes to
main.js
and restart accordingly (i.e. a git or svn hook when code is updated).I am not aware about this hook. Can you please provide some link where i can get example for this or can you provide sample example for this?
This isn’t specific to Parse. Google
svn hooks
orgit hooks
for information on how to setup hooks. You can also take a look at the Node watch module for a different approach.Okay I will look for this.Thanks for quick reply.It helped 🙂
hi niraj, thanks for the article but i want to ask you :
1. where i can get this ??
appId: ‘{YOUR_APP_ID}’,
masterKey: ‘{YOUR_APP_MASTER_KEY}’,
fileKey: ‘optionalFileKey’
i clone the source parse.com from their github but i confused to get appid, masterkey and filekey ?
You get the
appId
andmasterKey
from your existing Parse.com app (see App Settings), or you just make it up if you don’t have a previous app.Hi, Great tutorial,
Is it possible to set up the Parse server with some kind of high availability? I have seen PM2 being used but it looks pretty complicated.
Thanks
I would recommend use of
pm2
, but it’s quite easy to get started. It’s can get complicated if you are trying to achieve something complex, but for now you can start with:pm2 start app.js
Hello @niraj,
i got {“error”:”unauthorized”} response, but when i try curl example i get response saying, connection refused by server.
can you help me ?
You need to make sure the
appId
andmasterKey
are the same in your app and server. Edit theapp.js
file as per my tutorial.