Tutorial - How to Setup Strapi Backend with Mongodb

May 01, 2021

Introduction

In this step-by-step tutorial, we will setup strapi headless CMS

Some of the advantages of using Strapi:

  • You can define a content type and many custom fields.
  • You get ready-made REST APIs for all those content types
  • Every data is available through REST APIs
  • All basic CRUD operations are available to you by just defining a content type.
  • And the most important step is the security. It provides authentication layer build-in. You don’t have to worry about writing code for authentication.

Lets start.

Pre-requisites

You need to have following installed:

  • node.js
  • docker

First run MongoDB

I will use docker for running MongoDB, and use following docker-compose.yml file

version: '3.3'
services:
  mongodb:
    image: mongo:4
    ports:
      - "27017:27017"
    volumes:
      - ./mongo:/data/db

And, run mongodb by following command:

docker-compose up -d

Install Strapi with Mongodb

Lets create a Strapi project, and call it api

npx create-strapi-app api

Following are the screenshots for next steps, (choosing mongodb installation and others).

Choose your installation type: Custom

Strapi Installation

Choose Mongodb

Strapi Mongodb

Mongodb Configuration

Strapi Mongodb Configuration

Run Strapi Project in Development mode

npm run develop

It will run the server on http://localhost:1337/ Open it in your browser.

Strapi Server

Register yourself as admin.

Once you open the url: http://localhost:1337/, you will see admin panel. Now you can configure your backend, and can create new content types.


Similar Posts

Latest Posts