Building a music app Part 3: Creating the Back-end with Prisma, Express & Nexus
To build the back-end of the music app, I needed to work with a database, and I also needed to set up a server.
In my case, I decided to use Prisma, an ORM that makes working with databases really simple, as well as Express.
Setting up Prisma
Using Prisma makes working with databases very simple. I used this ORM to quickly set up a SQLite database with few command using the CLI.
Once we initialize Prisma using the npx prisma init command, we get a new blank schema.prisma file with few instructions on how to plan our database schema.
More on Prisma here.
Setting up Express
To Set up Express, I installed it using npm, then I created a GraphQL endpoint in the main server.ts file. Because I am GraphQL, which uses a single endpoint, I didn't need to create new routes and endpoints.
Building the GraphQL schema with Nexus
GraphQL schema is where we define our Object Types (Queries and mutations) and resolvers.
Nexus automatically generates a schema while providing additional benefits like type safety.
Testing the API
To test the API, Express provides us with a very useful playground interface to test our queries and mutations, to access the playground simple go to the endpoint URL http://localhost:4000/api/graphql
Get the code
The full source code of the Express server is available here.