The PEAN Stack with GraphQL


It's not something new, but it is definitely not as popular as variants like MEAN and LAMP.
The PEAN stack, consisting of PostgreSQL, Express, NodeJS, and Angular can be great if NoSQL isn't sufficient.

This was the case in my finals project and I was required to use a relational database, as well as an MVC framework for the frontend. To speed up the configuration on this part I used a BaaS solution called Supabase. It includes a Postgres database with nearly full access to it and a neat UI. It also offers a bunch of other features and even a native Postgres extension that enables easy usage of GraphQL directly from the client.

As I was primarily using Supabase only for the database, auth and email confirmation, I wanted to create an own GraphQL server and have the client requests go indirectly to the database to avoid using Supabase's API in the client code. Although this creates an additional single point of failure, it also adds a bit more flexibility and less dependance on the backend service provider (plus me being a little too ambitious for this project). Since there's already a library that does all the work of creating a GraphQL API for a Postgres database and is even able to update itself, I added it as middleware to an Express server. This library is called Postgraphile and it offers all the functionality needed for this composition.

So all together I created the following diagram:


For the host machine I simply created a VPS on DigitalOcean with 1GB memory. I can highly recommend this platform for learning and experimenting! After the initial setup, such as firewall and SSH access, I installed all the required software, including:

  • Caddy - an easy-to-use open source web server with automatic HTTPS
  • PM2 - a production process manager for Node.js applications
  • NVM - a version manager to install Node.js

In this post there's a detailed description of this setup without the database. Another difference is that for this project I used a self-written deploy script instead of the one included in PM2.




You'll only receive email when they publish something new.

More from Cili's Notes
All posts