{"id":2034,"date":"2026-07-22T00:31:03","date_gmt":"2026-07-21T17:31:03","guid":{"rendered":"https:\/\/sumberlaba.com\/index.php\/2026\/07\/22\/how-to-build-a-full-stack-app-with-mern-a-step-by-step-tutorial\/"},"modified":"2026-07-22T00:31:03","modified_gmt":"2026-07-21T17:31:03","slug":"how-to-build-a-full-stack-app-with-mern-a-step-by-step-tutorial","status":"publish","type":"post","link":"https:\/\/sumberlaba.com\/index.php\/2026\/07\/22\/how-to-build-a-full-stack-app-with-mern-a-step-by-step-tutorial\/","title":{"rendered":"How to Build a Full-Stack App with MERN: A Step-by-Step Tutorial"},"content":{"rendered":"<h1>How to Build a Full-Stack App with MERN: A Step-by-Step Tutorial<\/h1>\n<p>The MERN stack (MongoDB, Express.js, React, Node.js) is a powerful, JavaScript-only set of technologies for building modern web applications. This tutorial walks you through creating a simple CRUD app, from backend API to frontend UI. By the end, you&#8217;ll have a functional full-stack application running locally.<\/p>\n<h2>1. Set Up the Backend with Node.js and Express<\/h2>\n<p>Start by initializing a new Node project. Create a folder named <code>server<\/code> and run <code>npm init -y<\/code>. Install the core dependencies:<\/p>\n<ul>\n<li><strong>express<\/strong> \u2013 for routing and middleware<\/li>\n<li><strong>mongoose<\/strong> \u2013 to connect and interact with MongoDB<\/li>\n<li><strong>cors<\/strong> \u2013 to allow cross-origin requests from React<\/li>\n<li><strong>dotenv<\/strong> \u2013 to manage environment variables<\/li>\n<\/ul>\n<p>Create an <code>index.js<\/code> file, import Express, and set up a basic server listening on port 5000. Use <code>mongoose.connect()<\/code> to link to your local MongoDB instance, then define a simple schema (e.g., for a Task model with title and completed fields).<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/via.placeholder.com\/800x600\/4a90d9\/ffffff?text=how%20to%20build%20a%20full-stack%20app%20with%20MERN\" alt=\"Article illustration\" style=\"display:block;margin:20px auto;max-width:100%;height:auto;border-radius:8px;\" \/><\/p>\n<h2>2. Build RESTful API Endpoints<\/h2>\n<p>With Express and Mongoose in place, create routes inside a <code>routes<\/code> folder. Use a router to define:<\/p>\n<ul>\n<li><strong>GET \/api\/tasks<\/strong> \u2013 fetch all tasks<\/li>\n<li><strong>POST \/api\/tasks<\/strong> \u2013 add a new task<\/li>\n<li><strong>PUT \/api\/tasks\/:id<\/strong> \u2013 update a task<\/li>\n<li><strong>DELETE \/api\/tasks\/:id<\/strong> \u2013 delete a task<\/li>\n<\/ul>\n<p>Implement each route using Mongoose methods (e.g., <code>Task.find()<\/code>, <code>Task.create()<\/code>). Test your API with Postman or cURL before moving to the frontend.<\/p>\n<h2>3. Scaffold the React Frontend<\/h2>\n<p>Create a React app using <code>create-react-app<\/code> (or Vite) in a separate <code>client<\/code> folder. Install <code>axios<\/code> for HTTP requests. Build components:<\/p>\n<ul>\n<li><strong>App.js<\/strong> \u2013 main wrapper with state and useEffect to fetch tasks<\/li>\n<li><strong>TaskList.js<\/strong> \u2013 renders tasks from state<\/li>\n<li><strong>TaskForm.js<\/strong> \u2013 input form to add new tasks<\/li>\n<\/ul>\n<p>Use <code>axios.get('http:\/\/localhost:5000\/api\/tasks')<\/code> to load data on component mount, and similar calls for POST, PUT, DELETE.<\/p>\n<h2>4. Connect Frontend to Backend<\/h2>\n<p>Ensure CORS is enabled in your Express app (<code>app.use(cors())<\/code>). In React, proxy API requests to avoid CORS issues in development by adding <code>\"proxy\":\"http:\/\/localhost:5000\"<\/code> to your client&#8217;s <code>package.json<\/code>. Now your React app can call endpoints without full URLs.<\/p>\n<p>Run both servers (backend on port 5000, frontend on port 3000) using separate terminals. The frontend will now display data from MongoDB, and you can create, update, and delete tasks in real time.<\/p>\n<h2>Conclusion<\/h2>\n<p>You&#8217;ve built a complete MERN stack app with a RESTful API and a reactive UI. This pattern can be extended with authentication, more complex schemas, or additional features. The key takeaway is how seamlessly JavaScript works across the full stack.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to Build a Full-Stack App with MERN: A Step-by-Step Tutorial The MERN stack (MongoDB, Express.js, React, Node.js) is a powerful, JavaScript-only set of technologies for building modern web applications. This tutorial walks you through creating a simple CRUD app, from backend API to frontend UI. By the end, you&#8217;ll have a functional full-stack application &hellip; <\/p>\n","protected":false},"author":2716,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"footnotes":""},"categories":[],"tags":[],"class_list":["post-2034","post","type-post","status-publish","format-standard","hentry"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/sumberlaba.com\/index.php\/wp-json\/wp\/v2\/posts\/2034","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sumberlaba.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sumberlaba.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sumberlaba.com\/index.php\/wp-json\/wp\/v2\/users\/2716"}],"replies":[{"embeddable":true,"href":"https:\/\/sumberlaba.com\/index.php\/wp-json\/wp\/v2\/comments?post=2034"}],"version-history":[{"count":0,"href":"https:\/\/sumberlaba.com\/index.php\/wp-json\/wp\/v2\/posts\/2034\/revisions"}],"wp:attachment":[{"href":"https:\/\/sumberlaba.com\/index.php\/wp-json\/wp\/v2\/media?parent=2034"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sumberlaba.com\/index.php\/wp-json\/wp\/v2\/categories?post=2034"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sumberlaba.com\/index.php\/wp-json\/wp\/v2\/tags?post=2034"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}