|
| 1 | +# parse-server-example |
| 2 | + |
| 3 | +Example project using the parse-server module on Express. |
| 4 | + |
| 5 | +### For Local Development |
| 6 | + |
| 7 | +* Make sure you have at least Node 4.1. `node --version` |
| 8 | +* Clone this repo and change directory to it. |
| 9 | +* `npm install` |
| 10 | +* Install mongo locally using http://docs.mongodb.org/master/tutorial/install-mongodb-on-os-x/ |
| 11 | +* Run `mongo` to connect to your database, just to make sure it's working. Once you see a mongo prompt, exit with Control-D |
| 12 | +* Run the server with: `npm start` |
| 13 | +* By default it will use a path of /parse for the API routes. To change this, or use older client SDKs, run `export PARSE_MOUNT=/1` before launching the server. |
| 14 | +* You now have a database named "dev" that contains your Parse data |
| 15 | +* Install ngrok and you can test with devices |
| 16 | + |
| 17 | +### Getting Started With Heroku + Mongolab Development |
| 18 | + |
| 19 | +* Clone the repo and change directory to it |
| 20 | +* Use the Heroku Toolbelt to log in and prepare the app |
| 21 | +* Use the MongoLab addon: `heroku addons:create mongolab:sandbox` |
| 22 | +* Use `heroku config` and note the URI provided by MongoLab under the var MONGOLAB_URI |
| 23 | +* Copy this URI and set it as a new config variable: `heroku config:set DATABASE_URI=mongodb://...` |
| 24 | +* By default it will use a path of /parse for the API routes. To change this, or use older client SDKs, run `heroku config:set PARSE_MOUNT=/1` |
| 25 | +* Deploy it with: `git push heroku master` |
| 26 | + |
| 27 | +### Using it |
| 28 | + |
| 29 | +You can use the REST API, the JavaScript SDK, and any of our open-source SDKs: |
| 30 | + |
| 31 | +Example request to a server running locally: |
| 32 | + |
| 33 | +``` |
| 34 | +curl -X POST \ |
| 35 | + -H "X-Parse-Application-Id: myAppId" \ |
| 36 | + -H "Content-Type: application/json" \ |
| 37 | + -d '{"score":1337,"playerName":"Sean Plott","cheatMode":false}' \ |
| 38 | + http://localhost:1337/parse/classes/GameScore |
| 39 | +``` |
| 40 | + |
| 41 | +Example using it via JavaScript: |
| 42 | + |
| 43 | +``` |
| 44 | +Parse.initialize('myAppId','unused'); |
| 45 | +Parse.serverURL = 'https://whatever.herokuapp.com'; |
| 46 | +var obj = new Parse.Object('GameScore'); |
| 47 | +obj.set('score',1337); |
| 48 | +obj.save().then(function(obj) { |
| 49 | + console.log(obj.toJSON()); |
| 50 | + var query = new Parse.Query('GameScore'); |
| 51 | + query.get(obj.id).then(function(objAgain) { |
| 52 | + console.log(objAgain.toJSON()); |
| 53 | + }, function(err) {console.log(err); }); |
| 54 | +}, function(err) { console.log(err); }); |
| 55 | +``` |
| 56 | + |
| 57 | +You can change the server URL in all of the open-source SDKs, but we're releasing new builds which provide initialization time configuration of this property. |
0 commit comments