Build an Application Like Google Docs Using React and MongoDB
Last Updated : 23 Jul, 2025
In this article, we will create applications like Google Docs Made In React and MongoDB. This project basically implements functional components and manages the state accordingly. The user uses particular tools and format their document like Google Docs and save their work as well. The logic of Google Docs is implemented using JSX and Quill.
Preview of Final Output:
Build an Application Like Google Docs Made In React and MongoDB
Approach To Build a Docs Application Using React and MongoDB
For a Backend App
index.js: Sets up Socket.IO server, handles client connections, and defines event listeners for "get-document", "send-changes", and "save-document". It interacts with MongoDB through controllers.
documentSchema.js: Defines MongoDB schema for documents with _id and data fields.
db.js: Establishes MongoDB connection using Mongoose.
document-controller.js: Provides functions to interact with MongoDB. getDocument retrieves or creates a document by ID. updateDocument updates a document with new data.
For a Frontend App
App.js: Manages routing and initial document creation, directing users to a unique document editor page upon visiting the root URL.
Editor.jsx: Implements a document editor interface using Quill.js and manages real-time collaboration through Socket.IO. Handles document loading, content changes, and autosave functionality.
Steps to Create the Backend App And Installing Module
Step 1: Create directory for project.
mkdir Google-Docs-Clone
Step 2: Create sub directories for frontend and backend.
mkdir clientmkdir server
Step 3: Open backend directory using the following command.
cd server
Step 4: Initialize Node Package Manager using the following command.
npm init
Step 5: Install socket.io mongoose and dotenv package in backend using the following command.
npm install socket.io mongoose dotenv
Project Structure: Project Structure
The updated dependencies in package.json for backend will look like:
//db.jsimportmongoosefrom'mongoose';constConnection=async()=>{constURL=`TOUR DB URL HERE`;try{awaitmongoose.connect(URL);console.log('Database connected successfully');}catch(error){console.log('Error while connecting with the database ',error);}}exportdefaultConnection;
Example : Below is an example to Build an Application Like Google Docs Made In React.
HTML
<!-- index.html --><!DOCTYPE html><htmllang="en"><head><metacharset="utf-8"/><linkrel="icon"href="%PUBLIC_URL%/favicon.ico"/><metaname="viewport"content="width=device-width, initial-scale=1"/><metaname="theme-color"content="#000000"/><metaname="description"content="Web site created using create-react-app"/><linkrel="apple-touch-icon"href="%PUBLIC_URL%/logo192.png"/><linkrel="manifest"href="%PUBLIC_URL%/manifest.json"/><title>React App</title></head><body><noscript>You need to enable JavaScript to run this app.</noscript><divid="root"></div></body></html>
//Editor.jsximport{useEffect,useState}from'react';importQuillfrom'quill';import'quill/dist/quill.snow.css';import{Box}from'@mui/material';importstyledfrom'@emotion/styled';import{io}from'socket.io-client';import{useParams}from'react-router-dom';constComponent=styled.div` background: #F5F5F5;`consttoolbarOptions=[['bold','italic','underline','strike'],['blockquote','code-block'],[{'header':1},{'header':2}],[{'list':'ordered'},{'list':'bullet'}],[{'script':'sub'},{'script':'super'}],[{'indent':'-1'},{'indent':'+1'}],[{'direction':'rtl'}],[{'size':['small',false,'large','huge']}],[{'header':[1,2,3,4,5,6,false]}],[{'color':[]},{'background':[]}],[{'font':[]}],[{'align':[]}],['clean']];constEditor=()=>{const[socket,setSocket]=useState();const[quill,setQuill]=useState();const{id}=useParams();useEffect(()=>{constquillServer=newQuill('#container',{theme:'snow',modules:{toolbar:toolbarOptions}});quillServer.disable();quillServer.setText('Loading the document...')setQuill(quillServer);},[]);useEffect(()=>{constsocketServer=io('http://localhost:9000');setSocket(socketServer);return()=>{socketServer.disconnect();}},[])useEffect(()=>{if(socket===null||quill===null)return;consthandleChange=(delta,oldData,source)=>{if(source!=='user')return;socket.emit('send-changes',delta);}quill&&quill.on('text-change',handleChange);return()=>{quill&&quill.off('text-change',handleChange);}},[quill,socket])useEffect(()=>{if(socket===null||quill===null)return;consthandleChange=(delta)=>{quill.updateContents(delta);}socket&&socket.on('receive-changes',handleChange);return()=>{socket&&socket.off('receive-changes',handleChange);}},[quill,socket]);useEffect(()=>{if(quill===null||socket===null)return;socket&&socket.once('load-document',document=>{quill.setContents(document);quill.enable();})socket&&socket.emit('get-document',id);},[quill,socket,id]);useEffect(()=>{if(socket===null||quill===null)return;constinterval=setInterval(()=>{socket.emit('save-document',quill.getContents())},2000);return()=>{clearInterval(interval);}},[socket,quill]);return(<Component><BoxclassName='container'id='container'></Box></Component>)}exportdefaultEditor;