Creating Strapi App with PostgreSQL

Ceren Baysal
Doğuş Technology
Published in
5 min readJan 21, 2021

Today I’m going to tell a bit about Strapi and try to show how can we start and configure a Strapi application using the PostgreSQL database.

You will find the below contents with the article;

  1. What is Strapi
  2. Installing Postgres
  3. Create Strapi App
  4. What the application looks like

Let’s do this 🚀

  1. What is Strapi?

Strapi is a flexible, open-source Headless CMS that gives developers the freedom to choose their favorite tools and frameworks while also allowing editors to easily manage and distribute their content. By making the admin panel and API extensible through a plugin system, Strapi enables the world’s largest companies to accelerate content delivery while building beautiful digital experiences.

To see the demo from the Strapi youtube channel;

To see the documentation and learn more about the Strapi I suggest the link below;

2. Installing PostgreSQL

I use homebrew here, so you can install homebrew using the command;

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

We can go through with the postgres image we download by Homebrew or let Docker create an image for us automatically. To install PostgreSQL via Homebrew;

brew install postgres

I choose the way with Docker complete everything for us. Let’s create a docker container for Postgre, so if you don’t have Docker, you can download it easily;

Now we are ready to create a new docker container.

We fill the username for the database as “postgres” and the password as “123” and create the container;

docker run -d -p 5432:5432 — name strapi-postgre -e POSTGRES_PASSWORD=123 postgres

The Docker Image is created automatically and now we can see the container is running in the list of containers;

docker ps -a

Let’s create a new database in Postgres. Run the image with the below command;

docker exec -it strapi-postgre bash

Now we’ll create the database inside of the container;

psql -U postgres

The database is created. Now we can quit the Postgres by using \q and exit commands. Let’s check the database we created using the password “123”;

psql -h localhost -p 5432 -U postgres -W

To see the list of databases we can use “\l” command. We see the “strapidb” is here. Let’s continue with creating the Strapi app.

3. Creating a Strapi App

First of all “node, npm and yarn” should be installed. The versions should be;

NodeJS >= 10.16 <=12NPM >= 6.xYarn >= 1.22.x

Now we’re ready to run the command to see the magic;

strapi-projects % yarn create strapi-app my-strapi-app

The command line is asking us to choose the installation type as Quickstart or Custom. We choose Custom (manual settings) now, but you can try to choose Quickstart to let all the choices will be selected by Strapi.

We choose Postgres for the database client. The rest of the requirements should be like;

The host and port information (127.0.0.1:5432) is the default for Postgres.

Now the application is fully created and as you can see that we can start the application using the command;

yarn develop

Now the application is running and if we open the URL http://localhost:1337/admin we can see the login screen and we choose a username and password for the admin pages and login easily.

4. What the application looks like

We can see the source codes;

That’s all! Hope you find the article helpful.

The sources that help me a lot (I’m grateful);

Thanks for reading! 🚀

--

--