Steps to Create the Backend Node App

Step 1: Create a new React App

npx create-react-app <name of project>

Step 2: Navigate to the Project folder using:

cd <name of project>

Step 3: Installing Required Packages.

npm install express mongoose

The updated dependencies in package.json file will look like:

"dependencies": {
"express": "^4.17.1",
"mongoose": "^5.13.2"
},

Example: Below is the code for the backend server in nodejs

Javascript




// server/server.js
 
const express = require('express');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
 
const app = express();
const PORT = process.env.PORT || 5000;
 
// Connect to MongoDB
mongoose.connect('mongodb://localhost:27017/fundraiser', {
    useNewUrlParser: true,
    useUnifiedTopology: true,
});
 
// Define a Donation model
const Donation = mongoose.model('Donation', {
    amount: Number,
    description: String,
});
 
// Middleware to parse JSON
app.use(bodyParser.json());
 
// API routes
app.post('/api/donations', async (req, res) => {
    try {
        const { amount, description } = req.body;
 
        // Create a new donation
        const newDonation = new Donation({ amount, description });
        await newDonation.save();
 
        res.status(201).json(newDonation);
    } catch (error) {
        console.error(error);
        res.status(500).send('Internal Server Error');
    }
});
 
app.get('/api/donations', async (req, res) => {
    try {
        // Fetch all donations
        const donations = await Donation.find();
        res.json(donations);
    } catch (error) {
        console.error(error);
        res.status(500).send('Internal Server Error');
    }
});
 
// Start the server
app.listen(PORT, () => {
    console.log(`Server is running on http://localhost:${PORT}`);
});


Start the Backend Server using the following command.

node server.js

Fundraiser Platform using MERN

A fundraising application, often referred to as a “fundraiser application” or “crowdfunding platform,” is a software or web-based platform designed to facilitate the collection of funds for a specific cause, project, or campaign. These applications provide a digital space where individuals, organizations, or businesses can create fundraising campaigns and seek financial support from a wider audience, typically through online donations.

Preview of final output: Let us have a look at how the final application will look like.

Output

Similar Reads

Technologies Used:

Node Express React Mongo Html and Css...

Project Structure:

Project Structure...

Approach:

Project Initialization: Create a new folder for the project and navigate to it. Initialize a new Node.js project using npm init -y. Install necessary dependencies: express for the server and mongoose for MongoDB connection. Server Setup: Create a server folder. Inside server, create a server.js file. Set up an Express server in server.js. Connect to MongoDB using Mongoose. Set up middleware for parsing JSON. Create API routes to handle fundraising operations (create, list donations). Models: Inside server, create a models folder. Define a Donation model using Mongoose to represent donation data. API Routes: Inside server, create a routes folder. Create an api.js file within the routes folder to handle API routes. Implement routes for creating and fetching donations. Run the Backend: Start the Express server using node server/server.js....

Steps to Create the Backend Node App:

Step 1: Create a new React App...

Steps to Create the Frontend React App:

...

Contact Us