How to set up a Parse Server backend with Typescript.
May, 16 2022
Parse Server is a great way to quickly spin up a backend for your project. Parse is a Node based utility that sits on top of ExpressJS.
It abstracts a lot of the backend code for us so we can spend more time focusing on the front end code.
In combination with Parse, Typescript can really shine when dealing with our routing and database calls.
Let's walk through how to set up a Parse Server project using Typescript.
First, start by cloning the Parse Server Example project in a directory of your choosing.
parse-server-example directory to what ever you would like and open the folder in a code editor of your choice.
Install the dependencies:
Next, install the typescript compiler globally, if not already installed on your local machine.
Install our types for the Parse project.
tsconfig.json file to the root directory of your project with the following options:
src folder in the root directory of this project.
Move the entire
./cloud folder into
index.js into the
Notice how this matches the path defined in the
rootDir tsconfig options.
tsc command in your terminal (make sure to have typescript installed globally).
If everything works as expected, a
./dist folder should've been generated by the typescript compiler.
Finally, let's add the
dist folder to the
./.gitignore file so that we can be sure our code is compiled on the server each time we deploy.
Tell Parse where to find our compiled Typescript code
./package.json and update the
Replace contents of
functions.ts with the following. We're just adding the
any type to the request parameter for now to shut up our compiler.
tsc command in your root directory to confirm everything compiles correctly. You should see your
Try starting the server with an
npm run start command.
If everything is working as expected, we should see the server start, then error out after ~30 seconds because Parse could not connect to a MongoDB instance.
We will configure the MongoDB Atlas instance in the next section.