Run parse-server locally

Prerequisites

Before getting started, you need to make sure to:

  • Have NodeJs installed. Make sure to run a compatible version. Run node --version to see your version and check if it is a supported version by parse-server. In most use-cases we recommend v16.
  • Have a package manager installed like yarn or npm. In this guide and demo project we will be using yarn.

Setup your project

First, you need to copy the migration-demo-parse-server project.

This demo will include all the supported features, and will be updated once we release new feature.

Next, install the dependencies via:

yarn install

Then copy the .env.example file to .env and fill in the values

cp .env.example .env

  • MORALIS_API_KEY is the api key, that can be found in your Moralis dashboard (under account settings)
  • DATABASE_URI and REDIS_CONNECTION_STRING are described below and depend on the way on how you setup MongoDB and Redis.
  • RATE_LIMIT_xx variables are configurable depending on your needs to rate-limit the user.
  • CLOUD_PATH is a reference to the code of your cloud functions. By default this will be ./build/cloud/main.js and only exists after you run yarn build
  • MASTER_KEY and APPLICATION_ID are required for parse-server and can be any value to your choice. Make sure to never expose the MASTER_KEY

🚧

Make sure to never expose these values to the public. Especially the MASTER_KEY will give users access to the entire parse-server.

Setup MongoDB locally

The parse-server needs a database to store all the data. In this guide we will be using MongoDB, as this is also being used on the Moralis hosted servers. But you could change it to Postgres (see https://docs.parseplatform.org/parse-server/guide/#database).

You have several options to run MongoDB:

  • Install and run MongoDB locally (most flexible)
  • Use the mongodb-runner (easiest)
  • You can use a hosted mongoDB from Atlas (hosted)

A. Install and run MongoDB locally (most flexible)

This option gives you the most flexibility, but it requires a bit more work to setup. For a complete guide on how to setup MongoDB locally, see https://www.mongodb.com/docs/v6.0/installation/

B. Use the mongodb-runner (easiest)

🚧

Do not use this method in your production server. This database runner is only built for local development and testing

The easiest solution is to use the mongodb-runner that is included in the demo project. For more information about this, see https://github.com/mongodb-js/runner

To start an instance, run:

yarn dev:db-start

To stop the runner, run:

yarn dev:db-stop

By default this will start a MongoDB on port 27017.

Make sure to run this database when starting your app. And set the DATABASE_URI in your .env to mongodb://localhost:27017.

C. Use hosted MongoDB Atlas (hosted)

You can also use a hosted MongoDB for Atlas. For some hosting providers this is the only option to integrate MongoDB. But you can also use it for local development. (just make sure that you're not using the same database in local development as you are using in production).

  1. Signup for an account at https://www.mongodb.com/atlas
  2. Create a new database
  3. Get the connection string
Open your database and click the connect buttonOpen your database and click the connect button

Open your database and click the connect button

Choose "Connect to your application"Choose "Connect to your application"

Choose "Connect to your application"

Copy the URI and make sure to replace the username and passwordCopy the URI and make sure to replace the username and password

Copy the URI and make sure to replace the username and password

  1. Set the DATABASE_URI in your .env. Make sure to replace <username> and <password> to a user that has read and write access. This can be set in the "Database access" page.

Setup Redis locally

Redis is needed to utilise the rate-limit functionality. For this we are using the RedisCachaAdpater of parse-server (see https://docs.parseplatform.org/parse-server/guide/#rediscacheadapter).

You can opt-out of this dependency if you want to setup your rate-limit in any other way.

You have several options to run Redis:

  • Install and run Redis locally (most flexible)
  • Use hosted Redis Enterprise Cloud (hosted)

A. Install and run Redis locally (most flexible)

This option gives you the most flexibility, but it requires a bit more work to setup. For a complete guide on how to setup Redis locally, see https://redis.io/docs/getting-started/

Then before running your app, make sure to run Redis locally (see the getting-started guide on Redis on how to do this as it differs per operating system) and set the REDIS_CONNECTION_STRING in your .env. This could look something like redis://127.0.0.1:6379

B. Use hosted Redis Enterprise Cloud (hosted)

You can also use a hosted Redis via Redis Enterprise Cloud. For some hosting providers this is the only option to integrate Redis. But you can also use it for local development. (just make sure that you're not using the same database in local development as you are using in production).

  1. Signup for an account at https://redis.com/redis-enterprise-cloud/overview/
  2. Create a new database
  3. Setup a user with read and write access

Create the user, and make sure to store the username and password somewhere safe

  1. Get the connection string

  1. Set the REDIS_CONNECTION_STRING in your .env with the username, password and endpoint from the previous step. The result should look like 'redis://:@'

Run your server locally

After you've finished the previous steps, you can build your app with

yarn build

This will compile your code to /build. This step is required for cloud functions to work. Alternatively you can change the path to your cloud code in .env.

Run your app locally with:

yarn dev

This will compile your app and run it locally on your specified port in your .env (by default this is [<http://localhost:1337>](http://localhost:1337`)

👍

Now your server can be accessed on <http://localhost:1337/server>. To connect your frontend to this server you need to use this server url, and your specified app id from your .env


Did this page help you?