Make sure you have a compatible Node.js version installed. Run node --version to see your local Node.js version. Open the package.json file too see which version of Node.js this example repository requires at { engines": { "node": "<NODE_VERSION>" } }. Note that there may be other Parse Server version available that support older or newer Node.js versions, see the Parse Server compatibility table.
Run mongo to connect to your database, just to make sure it's working. Once you see a mongo prompt, exit with Control-D.
Launch Parse Server with npm start.
By default the API route will use /parse as a base. You can change this by setting the environment variable PARSE_MOUNT, for example in the CLI run run export PARSE_MOUNT=/app to set the path to app.
Your Parse Server is not running and is connected to your local database named dev in which the data is stored that you manage via Parse Server.
Helpful Scripts
These scripts can help you to develop your app for Parse Server:
npm run watch will start your Parse Server and restart if you make any changes.
npm run lint will check the linting of your cloud code, tests and index.js, as defined in .eslintrc.json.
npm run lint-fix will attempt fix the linting of your cloud code, tests and index.js.
npm run prettier will help improve the formatting and layout of your cloud code, tests and index.js, as defined in .prettierrc.
npm run test will run any tests that are written in /spec.
npm run coverage will run tests and check coverage. Output is available in the /coverage folder.
Remote Deployment
Heroku
Alternatively, to deploy manually:
Clone the repo and change directory to it
Log in with the Heroku Toolbelt and create an app: heroku create
Use the mLab addon: heroku addons:create mongolab:sandbox --app YourAppName
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
Deploy it with: git push heroku master
AWS Elastic Beanstalk
Alternatively, deploy your local changes manually:
Create an environment and pass in MongoDB URI, App ID, and Master Key: eb create --envvars DATABASE_URI=<replace with URI>,APP_ID=<replace with Parse app ID>,MASTER_KEY=<replace with Parse master key>
If you deployed Parse Server remotely, change the URL accordingly.
APIs and SDKs
Use the REST API, GraphQL API or any of the Parse SDKs to see Parse Server in action. Parse Server comes with a variety of SDKs to cover most common ecosystems and languages, such as JavaScript, Swift, ObjectiveC and Android just to name a few.
The following shows example requests when interacting with a local deployment of Parse Server. If you deployed Parse Server remotely, change the URL accordingly.
// Initialize SDKParse.initialize("YOUR_APP_ID","unused");Parse.serverURL='http://localhost:1337/parse';// Save objectconstobj=newParse.Object('GameScore');obj.set('score',1337);awaitobj.save();// Query objectconstquery=newParse.Query('GameScore');constobjAgain=awaitquery.get(obj.id);
Android
// Initialize SDK in the application classParse.initialize(newParse.Configuration.Builder(getApplicationContext())
.applicationId("YOUR_APP_ID")
.server("http://localhost:1337/parse/") // '/' important after 'parse'
.build());
// Save objectParseObjectobj = newParseObject("TestObject");
obj.put("foo", "bar");
obj.saveInBackground();
iOS / tvOS / iPadOS / macOS (Swift)
// Initialize SDK in AppDelegate
Parse.initializeWithConfiguration(ParseClientConfiguration(block: {
(configuration: ParseMutableClientConfiguration) ->Voidin
configuration.server="http://localhost:1337/parse/"// '/' important after 'parse'
configuration.applicationId="YOUR_APP_ID"
}))
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.
请发表评论