DEV Community

Cover image for React.js + Node.js + MongoDB CRUD example - MERN stack Application
bezkoder
bezkoder

Posted on • Updated on

React.js + Node.js + MongoDB CRUD example - MERN stack Application

In this tutorial, we're gonna build a MERN stack: React.js + Node.js + MongoDB CRUD Application with Express example. The back-end server uses Node.js + Express for REST APIs, front-end side is a React client with React Router, Axios & Bootstrap.

Full Article: https://bezkoder.com/react-node-express-mongodb-mern-stack/

React.js + Node.js + MongoDB CRUD example Overview

We will build a full-stack Tutorial Application in that:

  • Tutorial has id, title, description, published status.
  • User can create, retrieve, update, delete Tutorials.
  • There is a search box for finding Tutorials by title.

- Add an item:

react-node-js-mongodb-example-crud-mern-stack-create

- Show all items:

react-node-js-mongodb-example-crud-mern-stack-retrieve-all

– Click on Edit button to view details of an item:

react-node-js-mongodb-example-crud-mern-stack--retrieve

On this Page, you can:

  • change status to Published/Pending using Publish/UnPublished button
  • remove the object from MongoDB Database using Delete button
  • update this object's details on Database with Update button

react-node-js-mongodb-example-crud-mern-stack-update

- Search items by field 'title':

react-node-js-mongodb-example-crud-mern-stack-search

  • Check MongoDB Database:

react-node-js-mongodb-example-crud-mern-stack-database

MERN stack Architecture

Our React.js + Node.js + MongoDB CRUD application will follow this architecture:

react-node-js-mongodb-example-crud-mern-stack-architecture

  • Node.js Express exports REST APIs & interacts with MongoDB Database using Mongoose ODM.
  • React Client sends HTTP Requests and retrieves HTTP Responses using Axios, consumes data on the components. React Router is used for navigating to pages.

Video

This is brief instruction on React Node.js Express application running with MongoDB database.

Node.js Express MongoDB Back-end

These are APIs that Node.js Express App will export:

Methods Urls Actions
GET api/tutorials get all Tutorials
GET api/tutorials/:id get Tutorial by id
POST api/tutorials add new Tutorial
PUT api/tutorials/:id update Tutorial by id
DELETE api/tutorials/:id remove Tutorial by id
DELETE api/tutorials remove all Tutorials
GET api/tutorials?title=[kw] find all Tutorials which title contains 'kw'

React.js Front-end

react-node-js-mongodb-example-crud-mern-stack-client-overview

  • The App component is a container with React Router. It has navbar that links to routes paths.

  • TutorialsList component gets and displays Tutorials.

  • Tutorial component has form for editing Tutorial's details based on :id.

  • AddTutorial component has form for submission new Tutorial.

  • These Components call TutorialDataService methods which use axios to make HTTP requests and receive responses.

For more details, implementation and Github, please visit:
https://bezkoder.com/react-node-express-mongodb-mern-stack/

Further Reading

Run both projects in one place:
How to integrate React with Node.js Express on same Server/Port

With Pagination:

Alt Text

Security: MERN stack Authentication & Authorization

Or Serverless with Firebase:

Dockerize: Docker Compose React + Node.js Express + MongoDB example

Top comments (0)