javascript|May 01, 2021|1 min read

Tutorial - How to Setup Strapi Backend with Mongodb

TL;DR

Set up Strapi headless CMS with MongoDB using Docker, configure content types, and get ready-made REST APIs with built-in authentication.

Tutorial - How to Setup Strapi Backend with Mongodb

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.

Related Posts

Strapi Tutorial - How to Configure Slug to have Nice URLs for SEO

Strapi Tutorial - How to Configure Slug to have Nice URLs for SEO

Introduction In our previous posts, we have seen How to Create Article in Strapi…

How to Create Article by REST API and Configure only Author can Edit/Update/Delete articles

How to Create Article by REST API and Configure only Author can Edit/Update/Delete articles

Introduction In this post, we will see: create a test user Authenticate it via…

Tutorial - How to Create a Content-type, and Configure User Permissions for REST APIs

Tutorial - How to Create a Content-type, and Configure User Permissions for REST APIs

Introduction In this post, we will see how we can create a content type. And…

How to Deploy Strapi with Next.js Frontend with Nginx Proxy and URL Redirect with Docker

How to Deploy Strapi with Next.js Frontend with Nginx Proxy and URL Redirect with Docker

Agenda I will cover following in this post: Prepare Docker image for Next.js app…

How to use Draft.js WYSWYG with Next.js and Strapi Backend, Edit/Update Saved Article

How to use Draft.js WYSWYG with Next.js and Strapi Backend, Edit/Update Saved Article

Introduction This post is in contuation of our previous post: How to use Draft…

How to use Draft.js WYSWYG with Next.js and Strapi Backend, Create and View Article with Image Upload

How to use Draft.js WYSWYG with Next.js and Strapi Backend, Create and View Article with Image Upload

Introduction In this post, we will use in Next.js with strapi. And, we will…

Latest Posts

Claude Code Skills — Build a Better Engineering Workflow with AI-Powered Code Reviews, Security Scans, and More

Claude Code Skills — Build a Better Engineering Workflow with AI-Powered Code Reviews, Security Scans, and More

Most developers use Claude Code like a search engine — ask a question, get an…

Server Security Best Practices — Complete Hardening Guide for Production Systems

Server Security Best Practices — Complete Hardening Guide for Production Systems

Every breach post-mortem tells the same story: an unpatched service, a…

Building an AI Voicebot for Visitor Check-In — A Practical Guide to Handling the Messy Parts

Building an AI Voicebot for Visitor Check-In — A Practical Guide to Handling the Messy Parts

Every office lobby has the same problem: a visitor walks in, nobody’s at the…

Staff Engineer Study Plan for MAANG Interviews — The Complete 12-Week Roadmap

Staff Engineer Study Plan for MAANG Interviews — The Complete 12-Week Roadmap

If you’re a Senior Engineer (L5) preparing for Staff (L6+) roles at MAANG…

XSS and CSRF Explained — The Complete Guide with Real Attack Examples and Defenses

XSS and CSRF Explained — The Complete Guide with Real Attack Examples and Defenses

XSS and CSRF have been in the OWASP Top 10 for over a decade. They’re among the…

OWASP Top 10 (2021) — Every Vulnerability Explained with Code

OWASP Top 10 (2021) — Every Vulnerability Explained with Code

The OWASP Top 10 is the industry standard for web application security risks. If…