Local Environment Setup
This guide will teach you how to initially set up your own Moralis Server to then run it locally
More Info
Moralis Server is an extension of the Parse Server.
Prerequisites
Have Node.js installed. Make sure the version you installed is compatible with Parse Server. Run
node --version
to check it. In most use-cases we recommendv16
.Have a package manager installed like
yarn
ornpm
. In this guide we will be usingyarn
.
Get the sample project
To speed up the migration process, we have the parse-server-migration project ready for you.
This project includes all the supported features, and will be updated once we release a new feature.
Download it and open it with your code editor:
Install dependencies
Open the terminal and run:
Fill environment variables
To get the .env
file, run:
You will see something like this:
Next, we will go through the variables that you need to fill/modify for this local setup.
Never expose these values to the public. Especially not the MASTER_KEY
, as it would give users access to the entire server.
MORALIS_API_KEY
MORALIS_API_KEY
Get your API Key from your Moralis dashboard.
MASTER_KEY
MASTER_KEY
It is required for Parse Server and can be any value to your choice. For example:
APPLICATION_ID
APPLICATION_ID
It is required for Parse Server and can be any value to your choice. For example:
DATABASE_URI
DATABASE_URI
The self-hosted Moralis 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 server. See how you could also use Postgres.
For this local setup, you can use the mongodb-runner
to automatically create a database instance.
Do not use this method in a production environment as it is only built for local development and testing.
mongodb-runner
is already included in this project, so to start an instance run:
By default this will start a MongoDB on port 27017
so set DATABASE_URI
to:
You can stop the instance with:
Make sure to start the instance before running the server.
REDIS_CONNECTION_STRING
REDIS_CONNECTION_STRING
Redis is needed to utilise the rate-limit functionality. For this we are using the RedisCacheAdpater
of Parse Server.
You can opt-out of this dependency if you want to set up your rate-limit functionality in any other way.
See this complete guide on how to setup Redis locally. If you're on Windows we recommend following this amazing YouTube tutorial.
After running Redis locally, set REDIS_CONNECTION_STRING
to its URL, which will probably be:
Complete .env
.env
Your .env
file should look like this:
Run the server locally
First, compile your code with:
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 the CLOUD_PATH
environment variable but we will see that in a more advanced section.
Now you can run the server locally with:
Your server is compiled and running locally on your specified PORT
(by default http://localhost:1337
).
Now your server can be accessed on http://localhost:1337/server
Remember
With this local setup, the server is still not production-ready. Let's continue with the next step to make it so.
Last updated