Building Your First MERN Stack(MongoDB, Express JS, React JS, and Node JS)

Gayathri Gamage
3 min readAug 2, 2023

--

Hello friends,

Do you know how to create a MERN Stack? Do you know what a MERN Stack is? Do you know when you will need a MERN Stack?

I will discuss how to create a simple MERN Stack Application.

MERN Stack is a combination of four technologies: Mongo DB, Express JS, React JS, and Node JS.

Embarking on your web development journey, you’ll meet the MERN Stack a popular technology combination loved worldwide. Think of it as a toolkit, with each tool helping you build amazing websites. The M stands for MongoDB, a place to store data. E is for Express, a tool to make the server. R stands for React, which creates cool web pages. And N is for Node.js, a way to make your website work. When you learn MERN, you’re joining a big group of tech fans making cool stuff online.

Mongo DB: MongoDB is a document database with the scalability and flexibility that you want with the querying and indexing that you need

Express JS: A structured base designed to develop web applications and APIs.

React JS: A Javascript Front-end library for building user interfaces. Maintained by Facebook.

Node JS: A Javascript runtime built on Chrome’s V8 JS engine.

You might have come across another acronym that’s quite like MERN — it’s called MEAN. While MERN employs React to create user interfaces, MEAN takes a different pathusing Angular. Think of Angular as a versatile toolset, similar to React, that empowers you to design engaging buttons, interactive forms, and various exciting elements on your website. The rest of the stack — MongoDB, Express, and Node.js — work harmoniously just like before, ensuring a smooth and efficient performance for your web projects. So, if you’re inclined towards Angular, the MEAN stack is your gateway to crafting captivating online experiences.

Absolutely, I understand that you’re looking for a step-by-step guide for creating your first MERN stack application, with a topic name that is similar to “How to create your first MERN (MongoDB, Express JS, React JS, and Node JS) Stack.” Let’s go with “Building Your First MERN Stack Contact List.”

Building Your First MERN Stack Contact List

Step 1: Set Up Your Environment

  1. Install Node.js and MongoDB on your machine.

Step 2: Set Up Your Backend (Node.js and Express)

  1. Create a new directory for your project.
  2. Navigate to the project directory using the terminal.
  3. Initialize a new Node.js project: npm init -y
  4. Install necessary dependencies: npm install express mongoose
  5. Create a file named server.js and set up a basic Express server and MongoDB connection.

Step 3: Set Up Your Frontend (React)

  1. In the project directory, create a client directory: mkdir client && cd client
  2. Create a new React app: npx create-react-app .
  3. Modify src/App.js to create a Contact List component.

Step 4: Connect Frontend and Backend

  1. In the React app, make API requests to the backend to manage contacts.
  2. Create API routes in Express to handle contact-related requests.

Step 5: Run Your Application

  1. Start both the server and the React app: npm start in both the root and client directories.

--

--