Skip to content

Parse init #4960

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 49 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ Parse Server is an [open source version of the Parse backend](http://blog.parsep
Parse Server works with the Express web application framework. It can be added to existing web applications, or run by itself.

- [Getting Started](#getting-started)
- [Running Parse Server](#running-parse-server)
- [Locally](#locally)
- [Docker](#inside-a-docker-container)
- [Saving an Object](#saving-your-first-object)
- [Connect an SDK](#connect-your-app-to-parse-server)
- [Creating your first application](#creating-your-first-application)
- [Saving an Object](#saving-your-first-object)
- [Connect an SDK](#connect-your-app-to-parse-server)
- [Running elsewhere](#running-parse-server-elsewhere)
- [Sample Application](#parse-server-sample-application)
- [Parse Server + Express](#parse-server--express)
- [Logging](#logging)
- [Docker](#inside-a-docker-container)
- [Documentation](#documentation)
- [Configuration](#configuration)
- [Basic Options](#basic-options)
Expand All @@ -40,35 +39,43 @@ Parse Server works with the Express web application framework. It can be added t

# Getting Started

April 2016 - We created a series of video screencasts, please check them out here: [http://blog.parseplatform.org/learn/parse-server-video-series-april-2016/](http://blog.parseplatform.org/learn/parse-server-video-series-april-2016/)
Parse-Server is built on the top of node. Before you can get started, you should have the latest version of node and npm installed.
We always recommend you run your server on the LTS versions as we focus on providing the most stability on those versions.

The fastest and easiest way to get started is to run MongoDB and Parse Server locally.
You can find the latest versions of [node.js here](https://nodejs.org/en/).

## Running Parse Server
In order to be fully functional, `parse-server` requires a database to run. You'll need to either have [mongodb](https://www.mongodb.com/download-center) or [postgres](https://www.postgresql.org/download/) setup, locally or remotely.

### Locally
```
$ npm install -g parse-server mongodb-runner
$ mongodb-runner start
$ parse-server --appId APPLICATION_ID --masterKey MASTER_KEY --databaseURI mongodb://localhost/test
```
***Note:*** *If installation with* `-g` *fails due to permission problems* (`npm ERR! code 'EACCES'`), *please refer to [this link](https://docs.npmjs.com/getting-started/fixing-npm-permissions).*

There are many service providers that offer hosting of mongodb and postgres.

:warning: Before creating your first app, your DB should be accessible and running.

## Creating your first application

### Inside a Docker container
In order to create your first application, you can use the `@parse/init` project.

The `@parse/init` project is an interactive command line tool that bootstraps a functional parse-server setup on your local machine.

In order to create your first parse app in the `my-parse-app` folder, run the following command:

```sh
$ npx @parse/init my-parse-app
```
$ docker build --tag parse-server .
$ docker run --name my-mongo -d mongo
$ docker run --name my-parse-server --link my-mongo:mongo -d parse-server --appId APPLICATION_ID --masterKey MASTER_KEY --databaseURI mongodb://mongo/test
```

You can use any arbitrary string as your application id and master key. These will be used by your clients to authenticate with the Parse Server.
The script above will create a fully functional `parse-server` setup in `my-parse-app` folder with:

That's it! You are now running a standalone version of Parse Server on your machine.
- `package.json`: the nodejs package definition, that defines the dependencies for your project.
- `cloud`: the folder for your cloud code.
- `cloud/main.js`: the main entrypoint for cloud code.
- `public`: the folder for publicly accessible static contents.

**Using a remote MongoDB?** Pass the `--databaseURI DATABASE_URI` parameter when starting `parse-server`. Learn more about configuring Parse Server [here](#configuration). For a full list of available options, run `parse-server --help`.
You can start the server with the following command:

### Saving your first object
```sh
$ npm start
```

## Saving your first object

Now that you're running Parse Server, it is time to save your first object. We'll use the [REST API](http://docs.parseplatform.org/rest/guide), but you can easily do the same using any of the [Parse SDKs](http://parseplatform.org/#sdks). Run the following:

Expand Down Expand Up @@ -134,7 +141,7 @@ $ curl -X GET \

To learn more about using saving and querying objects on Parse Server, check out the [Parse documentation](http://docs.parseplatform.org).

### Connect your app to Parse Server
## Connect your app to Parse Server

Parse provides SDKs for all the major platforms. Refer to the Parse Server guide to [learn how to connect your app to Parse Server](https://github.com/parse-community/parse-server/wiki/Parse-Server-Guide#using-parse-sdks-with-parse-server).

Expand Down Expand Up @@ -201,6 +208,22 @@ Logs are also be viewable in Parse Dashboard.

**Want new line delimited JSON error logs (for consumption by CloudWatch, Google Cloud Logging, etc.)?** Pass the `JSON_LOGS` environment variable when starting `parse-server`. Usage :- `JSON_LOGS='1' parse-server --appId APPLICATION_ID --masterKey MASTER_KEY`

## Inside a Docker container

```
$ git clone https://github.com/parse-community/parse-server
$ cd parse-server
$ docker build --tag parse-server .
$ docker run --name my-mongo -d mongo
$ docker run --name my-parse-server --link my-mongo:mongo -d parse-server --appId APPLICATION_ID --masterKey MASTER_KEY --databaseURI mongodb://mongo/test
```

You can use any arbitrary string as your application id and master key. These will be used by your clients to authenticate with the Parse Server.

That's it! You are now running a standalone version of Parse Server on your machine.

**Using a remote MongoDB?** Pass the `--databaseURI DATABASE_URI` parameter when starting `parse-server`. Learn more about configuring Parse Server [here](#configuration). For a full list of available options, run `parse-server --help`.

# Documentation

The full documentation for Parse Server is available in the [wiki](https://github.com/parse-community/parse-server/wiki). The [Parse Server guide](http://docs.parseplatform.org/parse-server/guide/) is a good place to get started. If you're interested in developing for Parse Server, the [Development guide](http://docs.parseplatform.org/parse-server/guide/#development-guide) will help you get set up.
Expand Down
5 changes: 5 additions & 0 deletions parse-init/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"no-console": "off"
}
}
182 changes: 182 additions & 0 deletions parse-init/init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
#!/usr/bin/env node

const shell = require("shelljs");
const chalk = require("chalk");
const fs = require("fs");
const inquirer = require('inquirer');
const path = require('path');
const CWD = process.cwd();
const crypto = require('crypto');
const DEFAULT_MONGODB_URI = 'mongodb://127.0.0.1:27017/parse';
const CHECK = '✓';
const program = require('commander');

let useYarn = false;
if (shell.which("yarn")) {
useYarn = true;
}

function generateKey() {
return crypto.randomBytes(16).toString('hex');
}

function ok(message) {
console.log(chalk.green(`${CHECK} ${message}`));
}

async function getInstallationsDir({ directory, interactive }) {
let target_directory;
if (directory) {
target_directory = directory;
} else if (interactive) {
const answer = await inquirer.prompt([
{
type: 'input',
name: 'target_directory',
message: 'Enter an installation directory',
default: CWD,
},
]);
target_directory = answer.target_directory;
} else {
target_directory = './parse-server'
}
console.log(`This will setup parse-server in ${chalk.bold(target_directory)}`);
await confirm(`Do you want to continue?`);
console.log(`Setting up parse-server in ${chalk.bold(target_directory)}`);
return target_directory;
}

function getAppConfiguration({ interactive }) {
if (!interactive) {
return {
appName: 'My Parse Server',
appId: generateKey(),
masterKey: generateKey(),
databaseURI: DEFAULT_MONGODB_URI
};
}
const questions = [
{
type: 'input',
name: 'appName',
message: 'Enter your Application Name',
validate: (value) => {
return value && value.length > 0
}
},
{
type: 'input',
name: 'appId',
message: 'Enter your Application Id (leave empty to generate)',
default: generateKey(),
},
{
type: 'input',
name: 'masterKey',
message: 'Enter your Master Key (leave empty to generate)',
default: generateKey(),
},
{
type: 'input',
name: 'databaseURI',
message: 'Enter your Database URL (valid mongodb or postgres)',
default: DEFAULT_MONGODB_URI,
}
];

return inquirer.prompt(questions);
}

function confirm(message, defaults = true) {
return inquirer.prompt([
{
type: 'confirm',
name: 'continue',
message: message,
default: defaults,
}
]).then(result => {
if (!result.continue) {
process.exit(1);
}
});
}

async function main({
directory,
interactive,
}) {
let target_directory = await getInstallationsDir({ interactive, directory });
target_directory = path.resolve(target_directory);
if (fs.existsSync(target_directory)) {
console.log(chalk.red(`${chalk.bold(target_directory)} already exists.\naborting...`));
process.exit(1);
}

shell.mkdir(target_directory);

const config = await getAppConfiguration({ interactive });
const {
masterKey,
databaseURI
} = config;

// Cleanup sensitive info
delete config.masterKey;
delete config.databaseURI;

shell.cd(target_directory);

const packageContent = {
scripts: {
start: "node -r dotenv/config node_modules/.bin/parse-server config.js"
}
};
fs.writeFileSync(
target_directory + "/package.json",
JSON.stringify(packageContent, null, 2) + '\n'
);
ok('Added package.json');

fs.writeFileSync(
target_directory + '/config.js',
'module.exports = ' + JSON.stringify(config, null, 2) + ';\n'
);
ok('Added config.js');

fs.writeFileSync(
target_directory + '/.env',
`PORT=1337\nPARSE_SERVER_MASTER_KEY=${masterKey}\nPARSE_SERVER_DATABASE_URI=${databaseURI}\n`
)
ok('Added .env');

shell.mkdir(target_directory + '/cloud');
ok('Created cloud/');

fs.writeFileSync(target_directory + '/cloud/main.js', `// Cloud Code entry point\n`);
ok('Created cloud/main.js');
shell.mkdir(target_directory + '/public');
ok('Created public/');

if (useYarn) {
shell.exec("yarn add parse-server dotenv");
} else {
shell.exec("npm install parse-server dotenv --save");
}

console.log(chalk.green(`parse-server is installed in \n\t${target_directory}!\n`));
await confirm(`Do you want to start the server now?\nEnsure a database running on ${databaseURI}`);
if (useYarn) {
shell.exec("yarn start");
} else {
shell.exec("npm start");
}
}

program
.option('-i, --interactive', 'Configure manually')
.option('-d, --directory [directory]', 'The target directory where to create a new parse-server')
.parse(process.argv);

main(program);
Loading