~/javascript/strapi-backend-api-setup-mongodb.md

Tutorial - How to Setup Strapi Backend with Mongodb

1 min readMay 01, 2021by Gorav Singal#javascript#strapi#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.

$ subscribe --weekly

One deep dive a week, in your inbox

System design, AI engineering, trading systems and interview prep. Tested code, real numbers. Free, and you can unsubscribe any time.

or read it on gyanbyte.substack.com

Share

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…

Create Articles with Image Upload Using Draft.js, Next.js, and Strapi

Create Articles with Image Upload Using Draft.js, Next.js, and Strapi

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

Latest Posts

How to Stay Valuable as a Software Engineer in the AI Era: A Practical Playbook

How to Stay Valuable as a Software Engineer in the AI Era: A Practical Playbook

In the previous article I argued that AI is not killing software engineering…

How to Review AI-Generated Code: A Checklist for Catching What the Model Missed

How to Review AI-Generated Code: A Checklist for Catching What the Model Missed

A few months back I approved a PR that was almost entirely AI-generated. It…

How to Debug AI-Generated Code: Understand First, Fix Last

How to Debug AI-Generated Code: Understand First, Fix Last

In the last article I wrote about reviewing AI code before it goes in. This one…

The Future of Software Engineering: What AI Changes, What Stays, and Where the Jobs Go

The Future of Software Engineering: What AI Changes, What Stays, and Where the Jobs Go

Every few weeks somebody sends me a scary headline — “AI will replace all…

The Transactional Outbox Pattern: Never Lose an Event Again

The Transactional Outbox Pattern: Never Lose an Event Again

This is one of those patterns that looks like nothing until you get burnt once…

Event Sourcing, Explained: Store What Happened, Not Just the Final State

Event Sourcing, Explained: Store What Happened, Not Just the Final State

Here is a question I like to ask in interviews: your bank account shows a…