{"id":1432,"date":"2020-11-05T21:02:25","date_gmt":"2020-11-05T16:02:25","guid":{"rendered":"https:\/\/www.edopedia.com\/blog\/?p=1432"},"modified":"2025-09-16T04:02:41","modified_gmt":"2025-09-15T23:02:41","slug":"mern-stack-tutorial","status":"publish","type":"post","link":"https:\/\/www.edopedia.com\/blog\/mern-stack-tutorial\/","title":{"rendered":"MERN (MongoDB, Express, React, and Node.js) Stack Tutorial 2026"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p>Over the last decade, website development has significantly evolved. We now have access to new tech stacks with modern application architecture. One of them is a MERN stack.<\/p>\n\n\n\n<p>MERN stands for MongoDB, Express, React, and Node.js.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>MongoDB is a NoSQL database.<\/li><li>Express is a Node.js framework to develop the backend of websites.<\/li><li>React is a JavaScript library to build a front-end user interface.<\/li><li>Node.js enables us to execute JavaScript code on the server.<\/li><\/ul>\n\n\n\n<p>Since its inception, the MERN stack has ignited excitement among the developer community. That\u2019s why many existing companies and new startups are adopting it for their projects.<\/p>\n\n\n\n<p>In turn, it creates new opportunities for developers. I would recommend using the <a href=\"https:\/\/haystackapp.io\/\" rel=\"follow\">Haystack<\/a> app to find those opportunities. Basically, it connects employers with job seekers, especially the techies.<\/p>\n\n\n\n<p>For example, let\u2019s say you\u2019re looking for a <a href=\"https:\/\/haystackapp.io\/\" rel=\"follow\">React App<\/a> development job. Simply create an account with them for free and the app will intelligently match you with relevant job opportunities.<\/p>\n\n\n\n<p>As now you&#8217;re a bit familiar with its scope and earning potential. Let&#8217;s create a simple web app using MERN stack. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Create the Backend<\/h2>\n\n\n\n<p>At first, create a root folder that will hold the project files.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text\/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}\">mkdir mern_stack_app<\/pre><\/div>\n\n\n\n<p>Now, move inside that folder.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text\/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}\">cd mern_stack_app<\/pre><\/div>\n\n\n\n<p>Initialize npm to automatically generate a <strong>package.json<\/strong> file.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text\/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}\">npm init -y<\/pre><\/div>\n\n\n\n<p>At this point, we need to install some dependencies for the backend.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text\/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}\">npm install express mongoose cors<\/pre><\/div>\n\n\n\n<p>I would even recommend you to install nodemon to automatically restart the server whenever the source code is modified.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text\/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}\">npm install -g nodemon<\/pre><\/div>\n\n\n\n<p>Let\u2019s create an <strong>index.js<\/strong> file in the <strong>mern_stack_app<\/strong> folder and start writing some code. Basically, this code-snippet is used to setup a Node.js\/Express server.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text\/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;JavaScript&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;js&quot;}\">const express = require(&quot;express&quot;);\nconst app = express();\nconst cors = require(&quot;cors&quot;);\nconst PORT = 4000;\napp.use(cors());\napp.listen(PORT, function() {\n  console.log(&quot;Server is running on Port: &quot; + PORT);\n});<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Download and Install MongoDB<\/h3>\n\n\n\n<ol class=\"wp-block-list\" type=\"1\"><li>At first, go to <a href=\"https:\/\/www.mongodb.com\/download-center\/community?jmp=docs\">https:\/\/www.mongodb.com\/download-center\/community?jmp=docs<\/a>. Then, select the desired version and your OS. Finally, select the MSI file.<\/li><li>Click the download button.<\/li><li>When the .msi file is downloaded, simply run it.<\/li><li>Follow the step by step wizard to complete the installation.<\/li><li>Now you need to create a folder on your computer to store the database. Mostly, on the local machine, we use the <strong>C drive<\/strong>. So, let\u2019s create a new folder in the <strong>C drive<\/strong> and name it <strong>\u201cdata\u201d<\/strong>. Move inside that folder and create a sub-folder. This time name it <strong>\u201cdb\u201d<\/strong>. This is where the actual database will be stored.<\/li><\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Run MongoDB<\/h3>\n\n\n\n<ol class=\"wp-block-list\" type=\"1\"><li>Go to \u201cC:\\Program Files\\MongoDB\\Server\\4.2\\bin\\\u201d<\/li><li>Open a terminal and type the following command.<\/li><\/ol>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text\/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}\">mongod;<\/pre><\/div>\n\n\n\n<p>MongoDB will start on PORT 27017.<\/p>\n\n\n\n<p>To start the mongo shell. Open another terminal (Do not close the terminal where mongod is running).<\/p>\n\n\n\n<p>Again go to \u201cC:Program FilesMongoDBServer4.2bin\\\u201d and type the following command.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text\/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}\">mongo;<\/pre><\/div>\n\n\n\n<p>This command will run the mongo shell.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Inserting data<\/h3>\n\n\n\n<p>Let\u2019s create a database and insert data in it.<\/p>\n\n\n\n<p>Type the following command to create a database.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text\/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}\">use details<\/pre><\/div>\n\n\n\n<p>Let\u2019s insert a few documents in it.<\/p>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;application\/json&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;JSON&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;json&quot;}\">&quot;, &quot;age&quot; :29},{&quot;name&quot;: &quot;Mike&quot;, &quot;age&quot; :23}])\n{\n        &quot;acknowledged&quot; : true,\n        &quot;insertedIds&quot; : [\n                ObjectId(&quot;5da3267ed1ee0751c51aa0e4&quot;),\n                ObjectId(&quot;5da3267ed1ee0751c51aa0e5&quot;),\n                ObjectId(&quot;5da3267ed1ee0751c51aa0e6&quot;),\n                ObjectId(&quot;5da3267ed1ee0751c51aa0e7&quot;),\n                ObjectId(&quot;5da3267ed1ee0751c51aa0e8&quot;)\n        ]\n}<\/pre><\/div>\n<\/div><\/div>\n\n\n\n<p>We created a collection named \u201cdetails\u201d, and inserted five documents in it. Let\u2019s check.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;application\/json&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;JSON&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;json&quot;}\">db.details.find()\n{ &quot;_id&quot; : ObjectId(&quot;5da3267ed1ee0751c51aa0e4&quot;), &quot;name&quot; : &quot;John&quot;, &quot;age&quot; : 21 }\n{ &quot;_id&quot; : ObjectId(&quot;5da3267ed1ee0751c51aa0e5&quot;), &quot;name&quot; : &quot;Max&quot;, &quot;age&quot; : 32 }\n{ &quot;_id&quot; : ObjectId(&quot;5da3267ed1ee0751c51aa0e6&quot;), &quot;name&quot; : &quot;Lisa&quot;, &quot;age&quot; : 25 }\n{ &quot;_id&quot; : ObjectId(&quot;5da3267ed1ee0751c51aa0e7&quot;), &quot;name&quot; : &quot;Sam&quot;, &quot;age&quot; : 29 }\n{ &quot;_id&quot; : ObjectId(&quot;5da3267ed1ee0751c51aa0e8&quot;), &quot;name&quot; : &quot;Mike&quot;, &quot;age&quot; : 23 }<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Connecting to MongoDB using Mongoose<\/h3>\n\n\n\n<p>Earlier, we installed mongoose. Let\u2019s use mongoose to connect the server to MongoDB.<\/p>\n\n\n\n<p>First, we need to import mongoose in our file.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text\/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}\">const mongoose = require(&quot;mongoose&quot;);<\/pre><\/div>\n\n\n\n<p>Then, connect mongoose to the database using the connect() function.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text\/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;JavaScript&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;js&quot;}\">mongoose.connect(&quot;mongodb:\/\/127.0.0.1:27017\/details&quot;, {\n  useNewUrlParser: true\n});\n\nconst connection = mongoose.connection;<\/pre><\/div>\n\n\n\n<p>At last, we use the following function to tell us that the connection was successful.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text\/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;JavaScript&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;js&quot;}\">connection.once(&quot;open&quot;, function() {\n  console.log(&quot;Connection with MongoDB was successful&quot;);\n});<\/pre><\/div>\n\n\n\n<p>This is how the index.js file looks now.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text\/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;JavaScript&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;js&quot;}\">const express = require(&quot;express&quot;);\nconst app = express();\nconst cors = require(&quot;cors&quot;);\nconst PORT = 4000;\nconst mongoose = require(&quot;mongoose&quot;);\napp.use(cors());\n\nmongoose.connect(&quot;mongodb:\/\/127.0.0.1:27017\/details&quot;, {\n  useNewUrlParser: true\n});\n\nconst connection = mongoose.connection;\n\nconnection.once(&quot;open&quot;, function() {\n  console.log(&quot;Connection with MongoDB was successful&quot;);\n});\n\napp.listen(PORT, function() {\n  console.log(&quot;Server is running on Port: &quot; + PORT);\n});<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Creating a schema<\/h3>\n\n\n\n<p>Next step is to create a schema.<\/p>\n\n\n\n<p>In the same folder where index.js file is, create a new file \u201cmodel.js\u201d add the following code in it.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text\/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;JavaScript&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;js&quot;}\">const mongoose = require(&quot;mongoose&quot;);\nconst Schema = mongoose.Schema;\n\nlet detail = new Schema({\n  name: {\n    type: String\n  },\n  age: {\n    type: Number\n  }\n});\n\nmodule.exports = mongoose.model(&quot;detail&quot;, detail);<\/pre><\/div>\n\n\n\n<p>The model is ready and we need to import it in the index.js file. Add the following code in index.js file to do so.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text\/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;JavaScript&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;js&quot;}\">let detail = require(&quot;.\/model&quot;);<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Implementing endpoints<\/h3>\n\n\n\n<p>The server is ready and connection with MongoDB is established. Now we will implement the endpoint. As we discussed in the previous part, we will fetch the data from MongoDB. To fetch data, we have to use GET. Let\u2019s create a route handler for it.<\/p>\n\n\n\n<p>But first, we need a router for it. Add the following line before the connection part.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text\/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;JavaScript&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;js&quot;}\">const router = express.Router();<\/pre><\/div>\n\n\n\n<p>And add this line above app.listen() function.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text\/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;JavaScript&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;js&quot;}\">app.use(&quot;\/&quot;, router);<\/pre><\/div>\n\n\n\n<p>Now the router part is complete. Let\u2019s create the handler.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text\/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;JavaScript&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;js&quot;}\">router.route(&quot;\/getData&quot;).get(function(req, res) {\n  detail.find({}, function(err, result) {\n    if (err) {\n      res.send(err);\n    } else {\n      res.send(result);\n    }\n  });\n});<\/pre><\/div>\n\n\n\n<p>In this route handler, we used the find() method to retrieve all the documents from the details collection. The endpoint here is \u201c\/getData\u201d. To check the endpoint, we will use the postman tool. You can download this tool from www.getpostman.com.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Design the Frontend<\/h2>\n\n\n\n<p>The backend is ready, let\u2019s build the frontend.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Understanding the frontend<\/h3>\n\n\n\n<p>So before we start writing code for the frontend part, we need to understand, what we are going to build. Our frontend part will contain a button. When clicked on this button, data the details collection will de display below it. We will display the name and age from every document of the collection.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Creating the react application.<\/h3>\n\n\n\n<p>Go to the directory that contains the backend folder. In the same directory, run the following command in a terminal.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text\/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}\">npx create-react-app frontend<\/pre><\/div>\n\n\n\n<p>Here, \u201cfrontend\u201d is the name of the folder that contains the default react project template and the dependencies are also installed with it. Go to this folder and type the following command to run the react application.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text\/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}\">npm start<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Adding bootstrap<\/h3>\n\n\n\n<p>Well, we are not building an application with many stylings, but still, we will use bootstrap in it. To install the bootstrap, use the following command.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text\/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}\">npm install bootstrap<\/pre><\/div>\n\n\n\n<p>In the frontend folder, open the src folder. Then, open the App.js file. We need to import bootstrap here.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text\/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;JavaScript&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;js&quot;}\">import &quot;bootstrap\/dist\/css\/bootstrap.min.css&quot;;<\/pre><\/div>\n\n\n\n<p>Moreover, remove all the default code present in the App class.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Adding component<\/h3>\n\n\n\n<p>We will have one component in our application, that will contain the button. In the src folder, create a new directory and name it \u201ccomponents\u201d. Go to this folder and create a new file. Name it \u201cdetails\u201d.<\/p>\n\n\n\n<p>Add the following code in it.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text\/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;JavaScript&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;js&quot;}\">import React, { Component } from &quot;react&quot;;\n\nexport default class Details extends Component {\n  render() {\n    return (\n      &lt;div className=&quot;container-fluid&quot; style={{ marginTop: &quot;30px&quot; }}&gt;\n        &lt;div className=&quot;row&quot;&gt;\n          &lt;div className=&quot;col-xs-12\u2033 style={{ textAlign: &quot;center&quot; }}&gt;\n            &lt;button\n              className=&quot;btn btn-primary&quot;\n              style={{ position: &quot;absolute&quot;, marginLeft: &quot;50%&quot; }}\n            &gt;\n              Click\n            &lt;\/button&gt;\n          &lt;\/div&gt;\n        &lt;\/div&gt;\n      &lt;\/div&gt;\n    );\n  }\n}<\/pre><\/div>\n\n\n\n<p>Now, open the app.js file and import this component in it. And then use this component in the App function. This is how the app.js file will look.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text\/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;JavaScript&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;js&quot;}\">import React from &quot;react&quot;;\nimport &quot;.\/App.css&quot;;\nimport &quot;bootstrap\/dist\/css\/bootstrap.min.css&quot;;\nimport Details from &quot;.\/components\/details&quot;;\n\nfunction App() {\n  return &lt;Details \/&gt;;\n}\n\nexport default App;<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Connect Backend With Frontend<\/h2>\n\n\n\n<p>Frontend and backend are ready. Let\u2019s connect them.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Installing and using Axios<\/h3>\n\n\n\n<p>To connect both of them, we need the Axios library. Run the following command to install the Axios.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text\/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}\">npm install axios<\/pre><\/div>\n\n\n\n<p>Then, import Axios in the details.js file.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text\/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;JavaScript&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;js&quot;}\">import axios from &quot;axios&quot;;<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Completing the frontend<\/h3>\n\n\n\n<p>We will use the Axios to fetch data from the backend. We will use axios.get method. But first, we need to define a state in the constructor.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text\/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;JavaScript&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;js&quot;}\">this.state = {\n  data: [],\n  buttonClicked: false\n};<\/pre><\/div>\n\n\n\n<p>data: This will hold the details fetched from the backend. buttonClicked: This will be used to display data when the button is clicked.<\/p>\n\n\n\n<p>This is axios is used.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text\/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;JavaScript&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;js&quot;}\">axios.get(&quot;http:\/\/localhost:4000\/getData&quot;).then(res =&gt; {\n  this.setState({\n    data: res.data\n  });\n});<\/pre><\/div>\n\n\n\n<p>We used the same endpoint that we defined while creating the backend. When we get the response from the backend, we have to store the data in a state. We will store the data in this.state.data.<\/p>\n\n\n\n<p>To make this work properly, we will add this code in a lifecycle method known as componentDidMount(). This method executes before the first rendering.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text\/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;JavaScript&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;js&quot;}\">componentDidMount(){\n        axios.get('http:\/\/localhost:4000\/getData')\n        .then((res) =&gt;{\n         this.setState({\n             data: res.data\n         })\n        });\n    }<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Display data<\/h3>\n\n\n\n<p>Now, we have all the data. We just need to display it. Remember, the data returned is an array of objects. We have to iterate through it. We will display the data in the following way.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text\/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;JavaScript&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;js&quot;}\">        this.state.data.map((data)=&gt;{\n            return(\n            &lt;React.Fragment&gt;\n                &lt;p&gt; &lt;b&gt;name&lt;\/b&gt; : {data.name}&lt;\/p&gt;\n                &lt;p&gt;&lt;b&gt;age&lt;\/b&gt; : {data.age}&lt;\/p&gt;\n                &lt;hr\/&gt;\n            &lt;\/React.Fragment&gt;\n        )<\/pre><\/div>\n\n\n\n<p>Observe the code. We will iterate through this.state.data using the map method. Now we have to put this inside a condition. This code will only get executed when the button is clicked. And for this, we have this.state.buttonClicked.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text\/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;JavaScript&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;js&quot;}\">getDetails(){\n        if(!this.state.buttonClicked){\n        this.setState({\n            buttonClicked: true\n        })\n    }\n    }<\/pre><\/div>\n\n\n\n<p>This function will be executed when the button is clicked. It will change the value of this.state.buttonClicked to true and then data will get displayed on the screen.<\/p>\n\n\n\n<p>Let\u2019s add everything to the details.js file.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text\/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;JavaScript&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;js&quot;}\">import React, { Component } from &quot;react&quot;;\nimport axios from &quot;axios&quot;;\n\nexport default class Details extends Component {\n  constructor() {\n    super();\n    this.state = {\n      data: [],\n      buttonClicked: false\n    };\n    this.getDetails = this.getDetails.bind(this);\n  }\n\n  componentDidMount() {\n    axios.get(&quot;http:\/\/localhost:4000\/getData&quot;).then(res =&gt; {\n      this.setState({\n        data: res.data\n      });\n    });\n  }\n\n  getDetails() {\n    if (!this.state.buttonClicked) {\n      this.setState({\n        buttonClicked: true\n      });\n    }\n  }\n\n  render() {\n    return (\n      &lt;div className=&quot;container-fluid&quot; style={{ marginTop: &quot;30px&quot; }}&gt;\n        &lt;div className=&quot;row&quot;&gt;\n          &lt;div className=&quot;col-xs-12\u2033 style={{ textAlign: &quot;center&quot; }}&gt;\n            &lt;button\n              className=&quot;btn btn-primary&quot;\n              style={{ position: &quot;absolute&quot;, marginLeft: &quot;50%&quot; }}\n              onClick={this.getDetails}\n            &gt;\n              Click\n            &lt;\/button&gt;\n            &lt;div\n              className=&quot;container-fluid&quot;\n              style={{\n                position: &quot;absolute&quot;,\n                textAlign: &quot;center&quot;,\n                marginTop: &quot;50px&quot;\n              }}\n            &gt;\n              {this.state.buttonClicked\n                ? this.state.data.map(data =&gt; {\n                    return (\n                      &lt;React.Fragment&gt;\n                        &lt;p&gt;\n                          {&quot; &quot;}\n                          &lt;b&gt;name&lt;\/b&gt; : {data.name}\n                        &lt;\/p&gt;\n                        &lt;p&gt;\n                          &lt;b&gt;age&lt;\/b&gt; : {data.age}\n                        &lt;\/p&gt;\n                        &lt;hr \/&gt;\n                      &lt;\/React.Fragment&gt;\n                    );\n                  })\n                : null}\n            &lt;\/div&gt;\n          &lt;\/div&gt;\n        &lt;\/div&gt;\n      &lt;\/div&gt;\n    );\n  }\n}<\/pre><\/div>\n\n\n\n<p>This is how details.js file looks now.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Run the application<\/h3>\n\n\n\n<p>The frontend is ready, the backend is ready, and both are connected. Let\u2019s see how it looks in the browser.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1010\" height=\"395\" src=\"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2020\/11\/mern_stack_app_1.png\" alt=\"\" class=\"wp-image-1458\" srcset=\"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2020\/11\/mern_stack_app_1.png 1010w, https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2020\/11\/mern_stack_app_1-300x117.png 300w, https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2020\/11\/mern_stack_app_1-768x300.png 768w\" sizes=\"auto, (max-width: 1010px) 100vw, 1010px\" \/><\/figure>\n\n\n\n<p>Let\u2019s click on the button.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"441\" src=\"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2020\/11\/mern_stack_app_2-1024x441.png\" alt=\"\" class=\"wp-image-1459\" srcset=\"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2020\/11\/mern_stack_app_2-1024x441.png 1024w, https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2020\/11\/mern_stack_app_2-300x129.png 300w, https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2020\/11\/mern_stack_app_2-768x331.png 768w, https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2020\/11\/mern_stack_app_2.png 1027w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Everything works great!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>So we created a simple web application using the MERN stack. First, we created the backend using Node.js, mongoose, and MongoDB. Then, we created the frontend using React. Finally, we connected both of them using the Axios library.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Over the last decade, website development has significantly evolved. We now have access to new tech stacks with modern application architecture. One of them is a MERN stack. MERN stands for MongoDB, Express, React, and Node.js. MongoDB is a NoSQL database. Express is a Node.js framework to develop the backend of websites. React is &#8230; <a title=\"MERN (MongoDB, Express, React, and Node.js) Stack Tutorial 2026\" class=\"read-more\" href=\"https:\/\/www.edopedia.com\/blog\/mern-stack-tutorial\/\" aria-label=\"Read more about MERN (MongoDB, Express, React, and Node.js) Stack Tutorial 2026\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":1447,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[112],"tags":[],"class_list":["post-1432","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>MERN (MongoDB, Express, React, and Node.js) Stack Tutorial 2026<\/title>\n<meta name=\"description\" content=\"Introduction Over the last decade, website development has significantly evolved. We now have access to new tech stacks with modern application\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.edopedia.com\/blog\/mern-stack-tutorial\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"MERN (MongoDB, Express, React, and Node.js) Stack Tutorial [cy]\" \/>\n<meta property=\"og:description\" content=\"Introduction Over the last decade, website development has significantly evolved. We now have access to new tech stacks with modern application\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.edopedia.com\/blog\/mern-stack-tutorial\/\" \/>\n<meta property=\"og:site_name\" content=\"Edopedia\" \/>\n<meta property=\"article:author\" content=\"trulyfurqan\" \/>\n<meta property=\"article:published_time\" content=\"2020-11-05T16:02:25+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-09-15T23:02:41+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2020\/11\/mern_stack_tutorial-1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1024\" \/>\n\t<meta property=\"og:image:height\" content=\"578\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Furqan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Furqan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"MERN (MongoDB, Express, React, and Node.js) Stack Tutorial 2026","description":"Introduction Over the last decade, website development has significantly evolved. We now have access to new tech stacks with modern application","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.edopedia.com\/blog\/mern-stack-tutorial\/","og_locale":"en_US","og_type":"article","og_title":"MERN (MongoDB, Express, React, and Node.js) Stack Tutorial [cy]","og_description":"Introduction Over the last decade, website development has significantly evolved. We now have access to new tech stacks with modern application","og_url":"https:\/\/www.edopedia.com\/blog\/mern-stack-tutorial\/","og_site_name":"Edopedia","article_author":"trulyfurqan","article_published_time":"2020-11-05T16:02:25+00:00","article_modified_time":"2025-09-15T23:02:41+00:00","og_image":[{"width":1024,"height":578,"url":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2020\/11\/mern_stack_tutorial-1.jpg","type":"image\/jpeg"}],"author":"Furqan","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Furqan","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.edopedia.com\/blog\/mern-stack-tutorial\/#article","isPartOf":{"@id":"https:\/\/www.edopedia.com\/blog\/mern-stack-tutorial\/"},"author":{"name":"Furqan","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/person\/3951cb19e3aa56df09e408c98aa02339"},"headline":"MERN (MongoDB, Express, React, and Node.js) Stack Tutorial 2026","datePublished":"2020-11-05T16:02:25+00:00","dateModified":"2025-09-15T23:02:41+00:00","mainEntityOfPage":{"@id":"https:\/\/www.edopedia.com\/blog\/mern-stack-tutorial\/"},"wordCount":1375,"commentCount":1,"publisher":{"@id":"https:\/\/www.edopedia.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.edopedia.com\/blog\/mern-stack-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2020\/11\/mern_stack_tutorial-1.jpg","articleSection":["Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.edopedia.com\/blog\/mern-stack-tutorial\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.edopedia.com\/blog\/mern-stack-tutorial\/","url":"https:\/\/www.edopedia.com\/blog\/mern-stack-tutorial\/","name":"MERN (MongoDB, Express, React, and Node.js) Stack Tutorial [cy]","isPartOf":{"@id":"https:\/\/www.edopedia.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.edopedia.com\/blog\/mern-stack-tutorial\/#primaryimage"},"image":{"@id":"https:\/\/www.edopedia.com\/blog\/mern-stack-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2020\/11\/mern_stack_tutorial-1.jpg","datePublished":"2020-11-05T16:02:25+00:00","dateModified":"2025-09-15T23:02:41+00:00","description":"Introduction Over the last decade, website development has significantly evolved. We now have access to new tech stacks with modern application","breadcrumb":{"@id":"https:\/\/www.edopedia.com\/blog\/mern-stack-tutorial\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.edopedia.com\/blog\/mern-stack-tutorial\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.edopedia.com\/blog\/mern-stack-tutorial\/#primaryimage","url":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2020\/11\/mern_stack_tutorial-1.jpg","contentUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2020\/11\/mern_stack_tutorial-1.jpg","width":1024,"height":578,"caption":"MERN Stack Tutorial"},{"@type":"BreadcrumbList","@id":"https:\/\/www.edopedia.com\/blog\/mern-stack-tutorial\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.edopedia.com\/blog\/"},{"@type":"ListItem","position":2,"name":"MERN (MongoDB, Express, React, and Node.js) Stack Tutorial 2025"}]},{"@type":"WebSite","@id":"https:\/\/www.edopedia.com\/blog\/#website","url":"https:\/\/www.edopedia.com\/blog\/","name":"Edopedia","description":"Coding\/Programming Blog","publisher":{"@id":"https:\/\/www.edopedia.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.edopedia.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.edopedia.com\/blog\/#organization","name":"Edopedia","url":"https:\/\/www.edopedia.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2017\/10\/edopedia_icon_text_10.jpg","contentUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2017\/10\/edopedia_icon_text_10.jpg","width":400,"height":100,"caption":"Edopedia"},"image":{"@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/person\/3951cb19e3aa56df09e408c98aa02339","name":"Furqan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/e5e68aef3ad8f0b83d56f4953c512c8e57bd2e6dc64daec33b5d0495d9058f51?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/e5e68aef3ad8f0b83d56f4953c512c8e57bd2e6dc64daec33b5d0495d9058f51?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e5e68aef3ad8f0b83d56f4953c512c8e57bd2e6dc64daec33b5d0495d9058f51?s=96&d=mm&r=g","caption":"Furqan"},"description":"Well. I've been working for the past three years as a web designer and developer. I have successfully created websites for small to medium sized companies as part of my freelance career. During that time I've also completed my bachelor's in Information Technology.","sameAs":["http:\/\/www.edopedia.com\/blog\/","trulyfurqan"],"url":"https:\/\/www.edopedia.com\/blog\/author\/furqan\/"}]}},"_links":{"self":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts\/1432","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/comments?post=1432"}],"version-history":[{"count":2,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts\/1432\/revisions"}],"predecessor-version":[{"id":4049,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts\/1432\/revisions\/4049"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/media\/1447"}],"wp:attachment":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/media?parent=1432"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/categories?post=1432"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/tags?post=1432"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}