Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

Installing Strapi and Using MongoDB Atlas as Default Database

This article will talk about setting up your strapi project from your localhost and having your database hosted on Atlas.
This tutorial is geared and centered towards the latest Strapi version(v3).

Strapi is built with nodejs.

Requirements

  • NodeJs installed on your local Environment(14.x). It comes with npm wihich has npx prebuilt.
  • Atlas account (I will be using Mongo DB as the database)
  • 😉 And obviously you need a code IDE. ( I use VS code)

So. First things first, let go and set up a strapi instance our local environment. To create a strapi project, type this in your terminal:

npx create-strapi-app sharedhost 

I have decided to make my project name sharedhost in Desktop folder… You can create your strapi instance where ever location you want.

You will get this, all you have to do is navigate to Custom(Manual Settings)

You will be prompted again to choose your installation type, choose mongo

Now, you should have your Atlas Mongo DB credentials ready… Quickly go to Atlas and create a project and a cluster( Use Free Cluster for this sake of this tutorial)

After you create a cluster, take you to this page:

Since, this is a free cluster that I am using, you leave everything the default way it is and hit Create Cluster

Then, welcome!

They are few things you need to set in order to connect the just created cluster to your Strapi instance…

On the Security tab, select Database Access and create a user by deciding a username and password you want. (Keep this safe) Also allow the user to read and write the database…

Again, On the Security tab, select Network Access, add IP, address and select ALLOW ACCESS FROM ANYWHERE and confirm it( this will take about 3 minutes to be active)

Now, go to back to your clusters and click on connect, select Connect your application

Driver should be Node.js by default, and version should be 3.6 or later

The part I highlighted part in the immediate above screenshot is your host. It is the characters inbetween @ and

Yours will be different from mine as this….

BACK to your Terminal

Your database could be anything you want( by default, it takes your folder’s name)

Provide your host and make +srv connection to be true Next, provide your username and password

Enable SSL connection… That should be all you now wait for strapi to be installed along with all necessary node modules.

Run this command

npm run-script build

and then

npm run-script develop

If You did everything right, Strapi will automatically open in your default browser at http://localhost:1337/admin/auth/register-admin

Create your first administrator…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment