<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Samuelidowu on Medium]]></title>
        <description><![CDATA[Stories by Samuelidowu on Medium]]></description>
        <link>https://medium.com/@samuelidowu689?source=rss-ceeba3cb2549------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by Samuelidowu on Medium</title>
            <link>https://medium.com/@samuelidowu689?source=rss-ceeba3cb2549------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 22:05:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@samuelidowu689/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[From Zero to Hero: A Beginner’s Guide to Building Web Apps with the MERN Stack]]></title>
            <link>https://medium.com/@samuelidowu689/from-zero-to-hero-a-beginners-guide-to-building-web-apps-with-the-mern-stack-c31f00aa557b?source=rss-ceeba3cb2549------2</link>
            <guid isPermaLink="false">https://medium.com/p/c31f00aa557b</guid>
            <dc:creator><![CDATA[Samuelidowu]]></dc:creator>
            <pubDate>Fri, 27 Sep 2024 11:07:02 GMT</pubDate>
            <atom:updated>2024-09-27T11:07:02.285Z</atom:updated>
            <content:encoded><![CDATA[<p>Are you eager to dive into the world of full-stack web development but don’t know where to start? Look no further! This comprehensive MERN stack tutorial for beginners will guide you through the process of building web apps with the MERN stack, taking you from a novice to a confident developer.</p><p><strong>Introduction</strong></p><p>The MERN stack is a powerful combination of technologies used to build modern web applications. It consists of MongoDB, Express.js, React, and Node.js. By the end of this guide, you’ll understand how these components work together and be ready to create your own dynamic web applications.</p><p><strong>What is the MERN Stack?</strong></p><p>Before we dive into the details, let’s break down the MERN stack components:</p><p><strong>1.MongoDB</strong>: A flexible, scalable NoSQL database.</p><p><strong>2. Express.js</strong>: A backend web application framework for Node.js.</p><p><strong>3. React</strong>: A popular frontend JavaScript library for building user interfaces</p><p><strong>4. Node.js</strong>: A JavaScript runtime environment that executes code outside a web browser</p><p>Together, these technologies enable you to build full-stack JavaScript applications, making the development process more streamlined and efficient.</p><p><strong>Setting Up Your Development Environment</strong></p><p>To start building web apps with the MERN stack, you’ll need to set up your development environment:</p><p><strong>1. Install Node.js:</strong> Download and install Node.js from the official website.</p><p><strong>2. Install MongoDB</strong>: Follow the installation guide for your operating system on the MongoDB website.</p><p><strong>3. Choose a code editor:</strong> We recommend Visual Studio Code for its excellent JavaScript support.</p><p><strong>Building Your First MERN Stack Application</strong></p><p>Let’s create a simple todo list application to demonstrate how the MERN stack works together.</p><p><strong>Step 1: Setting Up the Backend</strong></p><p>First, we’ll create the server-side of our application using Node.js and Express.js.</p><ol><li>Create a new project directory and initialize a Node.js project:</li></ol><pre>mkdir mern-todo-app<br>cd mern-todo-app<br>npm init -y</pre><p>2. Install the necessary dependencies:</p><pre>npm install express mongoose cors</pre><p>3. Create a server.js file and set up a basic Express server:</p><pre>const express = require(&#39;express&#39;);<br>const cors = require(&#39;cors&#39;);<br>const mongoose = require(&#39;mongoose&#39;);<br>const app = express();<br>const PORT = process.env.PORT || 5000;<br>app.use(cors());<br>app.use(express.json());<br>mongoose.connect(&#39;mongodb://localhost/mern-todo&#39;, {<br> useNewUrlParser: true,<br> useUnifiedTopology: true,<br>});<br>app.listen(PORT, () =&gt; {<br> console.log(`Server is running on port ${PORT}`);<br>});</pre><p><strong>Step 2: Creating the MongoDB Schema</strong></p><p>Now, let’s define the schema for our todo items:</p><ol><li>Create a models folder and add a Todo.js file:</li></ol><pre>const mongoose = require(&#39;mongoose&#39;);<br>const TodoSchema = new mongoose.Schema({<br> text: {<br> type: String,<br> required: true,<br> },<br> completed: {<br> type: Boolean,<br> default: false,<br> },<br>});<br>module.exports = mongoose.model(&#39;Todo&#39;, TodoSchema);</pre><p><strong>Step 3: Implementing API Routes</strong></p><p>Next, we’ll create the API routes for our todo application:</p><ol><li>Create a routes folder and add a todos.js file:</li></ol><pre>const express = require(&#39;express&#39;);<br>const router = express.Router();<br>const Todo = require(&#39;../models/Todo&#39;);<br>// Get all todos<br>router.get(&#39;/&#39;, async (req, res) =&gt; {<br> try {<br> const todos = await Todo.find();<br> res.json(todos);<br> } catch (err) {<br> res.status(500).json({ message: err.message });<br> }<br>});<br>// Create a new todo<br>router.post(&#39;/&#39;, async (req, res) =&gt; {<br> const todo = new Todo({<br> text: req.body.text,<br> });<br> try {<br> const newTodo = await todo.save();<br> res.status(201).json(newTodo);<br> } catch (err) {<br> res.status(400).json({ message: err.message });<br> }<br>});<br>// Add more routes for updating and deleting todos<br>module.exports = router;</pre><p>2. Update server.js to use the new routes:</p><pre>const todosRouter = require(&#39;./routes/todos&#39;);<br>app.use(&#39;/api/todos&#39;, todosRouter);</pre><p>Step 4: Setting Up the Frontend with React</p><p>Now that our backend is ready, let’s create the frontend using React:</p><p>1. In the project root directory, create a new React app:</p><pre>npx create-react-app client<br>cd client</pre><p>2. Install additional dependencies:</p><pre>npm install axios</pre><p>3. Replace the contents of src/App.js with the following code:</p><pre>import React, { useState, useEffect } from &#39;react&#39;;<br>import axios from &#39;axios&#39;;<br>function App() {<br> const [todos, setTodos] = useState([]);<br> const [newTodo, setNewTodo] = useState(&#39;&#39;);<br> useEffect(() =&gt; {<br> fetchTodos();<br> }, []);<br> const fetchTodos = async () =&gt; {<br> const response = await axios.get(&#39;http://localhost:5000/api/todos&#39;);<br> setTodos(response.data);<br> };<br> const addTodo = async (e) =&gt; {<br> e.preventDefault();<br> await axios.post(&#39;http://localhost:5000/api/todos&#39;, { text: newTodo });<br> setNewTodo(&#39;&#39;);<br> fetchTodos();<br> };<br> return (<br> &lt;div className=&quot;App&quot;&gt;<br> &lt;h1&gt;MERN Stack Todo App&lt;/h1&gt;<br> &lt;form onSubmit={addTodo}&gt;<br> &lt;input<br> type=&quot;text&quot;<br> value={newTodo}<br> onChange={(e) =&gt; setNewTodo(e.target.value)}<br> placeholder=&quot;Enter a new todo&quot;<br> /&gt;<br> &lt;button type=&quot;submit&quot;&gt;Add Todo&lt;/button&gt;<br> &lt;/form&gt;<br> &lt;ul&gt;<br> {todos.map((todo) =&gt; (<br> &lt;li key={todo._id}&gt;{todo.text}&lt;/li&gt;<br> ))}<br> &lt;/ul&gt;<br> &lt;/div&gt;<br> );<br>}<br>export default App;</pre><p><strong>Running Your MERN Stack Application</strong></p><p>To run your application, follow these steps:</p><p>1. Start the backend server:</p><pre>node server.js</pre><p>2. In a separate terminal, start the React development server:</p><pre>cd client<br> npm start</pre><p>Your MERN stack todo application should now be up and running!</p><p><strong>Conclusion</strong></p><p>Congratulations! You’ve just built your first web app with the MERN stack. This tutorial has given you a solid foundation in full-stack JavaScript development. As you continue to explore and build with the MERN stack, you’ll discover its flexibility and power in creating modern web applications.</p><p>Remember, practice makes perfect. Keep experimenting with different features and functionalities to enhance your skills. Happy coding!</p><p><strong>Next Steps</strong></p><p>To further improve your MERN stack skills, consider the following:</p><p>1. Implement user authentication using JSON Web Tokens (JWT)</p><p>2. Add more complex CRUD operations to your todo app</p><p>3. Explore advanced React concepts like Redux for state management</p><p>4. Learn about deployment strategies for MERN stack applications</p><p>By continuing to build and learn, you’ll soon become a MERN stack expert!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c31f00aa557b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>