0% found this document useful (0 votes)
19 views36 pages

Yuvraj report

The document is a seminar report on 'MERN Stack Development' submitted by Yuvraj Jangid as part of his Bachelor of Engineering degree requirements. It covers the components, uses, and benefits of the MERN stack, which includes MongoDB, Express.js, React, and Node.js, and discusses web development technologies such as HTML, CSS, and JavaScript. The report also details the development of a full-stack web application, emphasizing the integration of front-end and back-end technologies.

Uploaded by

Yuvraj Tkd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views36 pages

Yuvraj report

The document is a seminar report on 'MERN Stack Development' submitted by Yuvraj Jangid as part of his Bachelor of Engineering degree requirements. It covers the components, uses, and benefits of the MERN stack, which includes MongoDB, Express.js, React, and Node.js, and discusses web development technologies such as HTML, CSS, and JavaScript. The report also details the development of a full-stack web application, emphasizing the integration of front-end and back-end technologies.

Uploaded by

Yuvraj Tkd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 36

A

Seminar Report on
“MERN Stack Development”

Submitted in Partial Fulfillment of the


Requirements for the award of degree of
Bachelor of Engineering in CSE

By

Submitted to: Submitted by:

Mr. Hemant Pareek Yuvraj Jangid


(21ESGCS098)

SOBHASARIA GROUP OF INSTITUTIONS, SIKAR

DEPARTMENT OF COMPUTER SCIENCE &

ENGINEERING SESSION: 2023-2024

i
ii
DECLARATION
I, Yuvraj Jangid, student of VI Semester Btech, in Computer Science and Engineering,
Sobhasaria Group of Institutions Sikar hereby declare that the Seminar entitled “MERN
Stack Development” has been carried out by me and submitted in partial fulfillment of the
requirements for the V Semester degree of Bachelor of Engineering in Computer Science
and Engineering of Bikaner Technical University, Bikaner during academic year 2022-2023.

Date : Name : Yuvraj Jangid


Place : Sikar(Rajasthan) Roll No : 21ESGCS098

iii
AKNOWLEDGEMENT
This is opportunity to express my heartfelt words for the people who were part of this
seminar in numerous ways, people who gave me unending support right from beginning of
the Seminar.
I am grateful to seminar coordinators Mr.Hemant Pareek for giving guidelines to make the
seminar successful. Without their guidance and persistent help this report would not have
been possible. I must acknowledge the faculties and staffs of Computer Science Engineering
from Sobhasaria Group of Institutions, Sikar.

I extend my thanks to Mr. Dileep K Agarwal Head of the Department for his cooperation
and guidance.

I want to give sincere thanks to the principal, Dr. L. Solanki for his valuablesupport.

Yours Sincerely,

Yuvraj Jangid

21ESGCS098

iv
TABLE OF CONTENTS
CHAPTER NO. TITLE PAGE NO.

CERTIFICATE ii
DECLARATION iii
ACKNOWLEDGEMENT iv
LIST OF FIGURES viii
ABSTRACT ix

1. INTRODUCTION……………………………………………………………1

1.1 What is MERN Stack?.............................................................................1

1.2 Components of MERN………………………………………………...1

1.3 Uses and benefits of MERN stack…………………………………..….1

1.4 Frontend vs. Backend development…………………………………….2 2.

Web Development Technologies…………………………………………….3 2.1

HTML: Structure of Web……………………………………………….3 2.1.1

Structure of an Html Document………………………………..3

2.1.2 Common HTML elements……………………………………..4

2.1.3 Semantic HTML……………………………………………….4 2.2

CSS: Styling the web…………………………………………………..4

2.2.1 Selectors and Properties……………………………………...4

2.2.2 Box Model……………………………………………………5

2.2.3 Responsive Design…………………………………………...5


v
2.2.4 CSS frameworks: Bootstrap………………………………….....6 2.3

Javascript: Adding Interactivity on Web…………………………….…6 2.3.1

Syntax and Basics…………………………………………….…6 2.3.2 DOM

manipulation……………………………………………..6 2.3.3 Event

handling………………………………………………….6

3. Frontend framework: React.js……………………………………………….8

3.1 Introduction to React………………………………………………………8

3.2 Setting up a React Application…………………………………………….8

3.3 Components and pops……………………………………………………..9

3.4 Making API calls from React……………………………………………...9

4. Setting up the Development Environment…………………………………...10

5. Building the Back-End with Node.js and Express.js………………….……..14

5.1 Introduction to Node.js………………………………………………….…14 5.2

Setting up Express Server…………………………………………………14 5.3

Building Restful APIs……………………………………………………..14 5.4

Error Handling and Debugging…………………………………………....15 6.

Getting Started with MongoDB……………………………………………….16

6.1 Introduction to NoSQL Database…………………...……………………...16

6.2 Setting up MongoDB………………………………………………………..16


6.3 CRUD operation in MongoDB……………………………………………...16

vi
6.4 Mongoose: Object Data Modeling (ODM)………………………………….17 7.

Connection of Frontend and Backend…………………………………….…..18

7.1 Integrating MongoDB with Express…………………..…………………….18 7.2

Fetching data from APIs………………………………………………….…18

7.3 Handling Form inputs and submission………………………………….….18 8.

Project : Event Planner Web Portfolio………………………………..………19 8.1

FrontEnd……………………………………………………………………..19 8.2

BackEnd……………………………………………………………………..20 8.3

Database……………………………………………………………………..20

9.CONCLUSION…………………………………………………...……………....23

REFERENCES……………………………………………………………….....24
vii
LIST OF FIGURES

S. NO. FIGURE NAME FIG.NO.

1. Components of MERN Fig- 1.1 2. Structure of HTML Fig- 2.1 3. Box Model
Fig- 2.2 4. Home Page Fig- 8.1 5. Service Page Fig- 8.2 6. Contact Page Fig- 8.3
7. Sever Connectivity Fig- 8.4 8. API Routing Fig- 8.5 9. Database Connectivity
Fig- 8.6 10. Database Interface Fig- 8.7
viii
ABSTRACT

The MERN stack, comprising MongoDB, Express.js, React, and Node.js, has emerged as a
popular framework for developing modern web applications due to its powerful, flexible, and
comprehensive nature. This project explores the development of a full-stack web application
using the MERN stack, illustrating the seamless integration of front-end and back-end
technologies to create a responsive, dynamic, and scalable web solution.

The application is designed to manage a hypothetical e-commerce platform, featuring user


authentication, product management, and real-time order processing. MongoDB, a NoSQL
database, serves as the foundation for storing and retrieving product and user data efficiently.
Express.js, a minimalist web framework for Node.js, is utilized to build robust RESTful APIs,
facilitating communication between the front end and the back end. React, a JavaScript
library for building user interfaces, ensures a responsive and interactive user experience by
efficiently updating and rendering components based on the application's state. Node.js, a
JavaScript runtime, provides the environment to execute server-side code, ensuring fast and
scalable network applications.

This project demonstrates the capabilities of the MERN stack in building a comprehensive
web application, emphasizing best practices in coding standards, data management, and
application deployment. Through this development process, the project highlights the
benefits of using a unified language, JavaScript, across the entire stack, which simplifies the
development workflow and enhances productivity. The resulting application not only
showcases the technical strengths of the MERN stack but also underscores its potential to
deliver high
performance, user-friendly web solutions in a variety of domains.

ix
CHAPTER – 1

INTRODUCTION

1.1 What is MERN Stack?

The MERN stack is a web development framework that consists of MongoDB, Express.js,
React, and Node.js. It enables developers to build full-stack JavaScript applications, where
both the client-side and server-side are written in JavaScript. This stack is popular for its
efficiency and ease of use in creating dynamic, single-page applications.

1.2 Components of MERN:

The components of the MERN stack are:

• MongoDB: A NoSQL database for storing data in a flexible, JSON-like format. •


Express.js: A lightweight web application framework for Node.js, used to build server
side applications.
• React: A JavaScript library for building user interfaces, particularly single-page
applications.
• Node.js: A JavaScript runtime that allows server-side scripting with JavaScript,
enabling the development of scalable network applications.

FIG :1.1

1.3 Uses and benefits of MERN stack:


Uses of MERN Stack:

• Single-Page Applications (SPAs): Ideal for creating dynamic and responsive SPAs
where the user experience is smooth and seamless.

1
• eCommerce Platforms: Suitable for developing eCommerce websites due to its
scalability and efficiency in handling large amounts of data.
• Social Media Applications: Perfect for building social networking sites and
applications with interactive features and real-time updates.
• Content Management Systems (CMS): Used for developing CMS that require a robust
and flexible back-end with an intuitive front-end.

Benefits of MERN Stack:

• Full-Stack JavaScript: Enables developers to use a single language (JavaScript) for


both client-side and server-side development, simplifying the development process. •
High Performance: Leveraging Node.js's non-blocking architecture and React's virtual
DOM, applications are fast and responsive.
• Ease of Use: React’s component-based architecture makes it easy to create reusable
components, while Express.js provides a minimalistic and flexible server framework. •
Scalability: MongoDB's schema-less nature allows for easy scaling and handling of large
amounts of data, making it suitable for growing applications.
• Open Source: All components of the MERN stack are open source and have strong
community support, providing extensive resources and tools for developers.

1.4 Frontend vs. Backend development

Front-End Development:

• Focus: Deals with the user interface and user experience of a website or application. •
Technologies: Uses HTML, CSS, JavaScript, and frameworks/libraries like React,
Angular, and Vue.js.
• Tasks: Involves designing the layout, styling, and interactive elements that users
directly interact with.

Back-End Development:

• Focus: Manages the server, database, and application logic, ensuring the smooth
operation of the website or application.
• Technologies: Uses languages and frameworks such as Node.js, Java and databases like
MongoDB, MySQL.
• Tasks: Involves creating and managing APIs, handling data storage, authentication, and
server-side functionality.

2
CHAPTER - 2

Web Development Technologies

2.1 HTML: Structure of Web

HTML (HyperText Markup Language) is the standard language used to create and design the
structure of web pages. It forms the backbone of all web pages and applications by providing
the basic structure and content. HTML provides the essential structure and content for web
pages, making it the foundation upon which other technologies like CSS and JavaScript build.

2.1.1 Structure of an HTML Document

An HTML document typically includes the following main components:

<!DOCTYPE html>: Declaration to define the document type and HTML


version. <html>: Root element that wraps the entire content.
<head>: Contains meta-information, title, links to stylesheets, and
scripts. <title>: Contains the title of the web page.
<body>: Contains the content displayed on the web page, including text, images, links, and
other media.

FIG 2.1

3
2.1.2 Common HTML Elements

Common HTML elements include:

• Headings: <h1> to <h6> for different levels of headings.


• Paragraphs: <p> for paragraphs.
• Links: <a> for hyperlinks.
• Images: <img> for embedding images.
• Lists: <ul> and <ol> for unordered and ordered lists, respectively, with <li> for list
items.
• Tables: <table>, <tr>, <td>, and <th> for creating and structuring tables. • Forms:
<form>, <input>, <label>, <textarea>, and <button> for user input forms. • Divisions
and Spans: <div> for block-level grouping and <span> for inline grouping.

2.1.3 Semantic HTML

Semantic HTML elements provide meaningful structure and context:

<header>: Defines a header for a document or section.


<nav>: Specifies a navigation section.
<main>: Represents the main content.
<section>: Groups related content thematically.
<article>: Represents a self-contained composition.
<aside>: Contains tangentially related content.
<footer>: Defines a footer for a document or section.

2.2 CSS: Styling the Web

CSS (Cascading Style Sheets) controls the presentation and layout of web pages. CSS is the
language used to describe the presentation of a document written in HTML. It controls the
layout, colors, fonts, and overall visual appearance of web pages, allowing developers to
create visually engaging and responsive websites. CSS separates the content (HTML) from
the presentation, allowing for cleaner and more maintainable code.

2.2.1 Selectors and Properties

Selectors target HTML elements to apply styles:

• Element Selector: Targets all instances of an element (e.g., p).


• Class Selector: Targets elements with a specific class (e.g., .classname). • ID
Selector: Targets an element with a specific ID (e.g., #idname). • Attribute
Selector: Targets elements based on an attribute (e.g., [type="text"]). •
Pseudo-class Selector: Targets elements based on their state (e.g., :hover).

4
Properties define the style rules applied to elements:

• Color: Sets text color.


• Background: Sets background color or image.
• Font: Sets font properties like size, weight, and family.
• Margin: Sets space around elements.
• Padding: Sets space inside elements.
• Border: Sets border properties.
2.2.2 Box Model

The CSS box model consists of:


Content Box: Area where text and images appear.
Padding Box: Space around the content inside the border.
Border Box: Border surrounding the padding and content.
Margin Box: Space outside the border, separating the element from others.

Fig 2.2

2.2.3 Responsive Design

Responsive design ensures web pages look good on various devices:

Fluid Layouts: Use relative units like percentages.


Media Queries: Apply styles based on viewport size (e.g., @media (max-width:
600px). Flexible Images: Make images scale within their containers.
Mobile-First Design: Start with styles for small screens and enhance for larger screens.

5
2.2.4 CSS Frameworks: Bootstrap

Bootstrap is a popular open-source front-end framework designed to facilitate the


development of responsive and mobile-first websites. Created by Twitter, Bootstrap provides
a collection of CSS and JavaScript components that help developers build web pages quickly
and efficiently.
Key Features of Bootstrap:-

• Responsive Design: Bootstrap's grid system and responsive design principles allow
websites to adapt to different screen sizes and devices seamlessly.

• Pre-styled Components: Bootstrap includes a wide range of pre-styled components such


as navigation bars, buttons, forms, modals, carousels, and more. These components are
designed to be easy to use and customize.

• Cross-browser Compatibility: Bootstrap is designed to work seamlessly across all modern


browsers and ensures consistent performance and appearance.
• Documentation: Bootstrap comes with extensive and well-organized documentation that
provides detailed examples and guidelines for using its components and features
effectively.

2.3 JavaScript: Adding Interactivity on Web

JavaScript is a high-level, versatile programming language primarily used to create


interactive and dynamic content on the web. It is an essential technology of the World Wide
Web, alongside HTML and CSS, and enables the development of modern web applications.

2.3.1 Importance of JavaScript

• Interactive Web Pages: JavaScript is crucial for creating interactive and user-friendly
web pages that engage users and provide a better browsing experience. • Rich Ecosystem:
The extensive ecosystem of libraries, frameworks, and tools enhances productivity and
allows developers to build sophisticated applications efficiently. • Versatility: Its ability to
run on both the client and server side makes JavaScript a versatile language suitable for
full-stack development.

2.3.2 DOM Manipulation

The Document Object Model (DOM) represents the structure of an HTML document as an
object-oriented tree. JavaScript can manipulate the DOM to dynamically change content,
structure, and styles of web pages. Common operations include selecting elements
(document.getElementById(), document.querySelector()), modifying element properties, and
adding or removing elements.

6
2.3.3 Event Handling

Event handling allows JavaScript to respond to user actions such as clicks, key presses, and
mouse movements. Event listeners (addEventListener()) are used to define what should
happen when an event occurs. This enables interactive behaviors like form validation,
dynamic content updates, and user interface enhancements.

How Event Handling Works

Here's a step-by-step overview of the event handling process:


1. Event Trigger: An event is triggered by a user interaction or other action on the web page.
2. Event Listener: An event listener is a function that is attached to an element on the page,
waiting for a specific event to occur.
3. Event Object: When an event occurs, an event object is created, which contains
information about the event, such as the type of event, the target element, and any other
relevant details.
4. Event Handler: The event listener calls an event handler function, passing the event object
as an argument.
5. Event Handler Execution: The event handler function executes, performing any
necessary actions in response to the event.

7
CHAPTER – 3
Frontend framework: React.js

3.1 Introduction to React

Definition: React.js is a JavaScript library for building user interfaces, especially for
single-page applications. It enables the creation of interactive and dynamic UIs through
reusable components.

Benefits:

• Efficiency:Enhances performance through an efficient update process. •


Reusability: Encourages modular and reusable code components.
• Community Support: Supported by a large and active community with extensive
resources.

3.2 Setting up a React Application

Tools and Setup:

Create React App: A command-line tool to set up a new React project with a
ready-to-use configuration.

Installation Steps:

Install Node.js and NPM: Required for managing dependencies and running

React. Create a New Project: Use Create React App to initialize the project.

Navigate to the Project Directory: Enter the project directory to start working.

Start the Development Server: Launch a local server to view and test the application
in the browser.

Project Structure:

src: Contains application code, including components and styles.

public: Includes static files like the HTML file.

Root Directory: Contains configuration and metadata files.

8
3.3 Components and Props

• Components:
o Definition: Reusable pieces of UI code that can be functional or class-based.
o Types:
▪ Functional Components: Defined as JavaScript functions that return
JSX.
▪ Class Components: Defined using ES6 classes with React.Component,
supporting lifecycle methods.
• Props:

• Definition:
Properties used to pass data from parent components to child
components.
• Usage:

▪ Passing Data: Done through attributes in the parent component.


▪ Accessing Data: Directly accessed in functional components and via
this.props in class components.
• State vs. Props:

• Props: Immutable data passed from parent to child.


• State: Mutable data managed within the component, reflecting internal changes.

3.4 Making API calls from React

1. Methods for API Calls:

• Fetch API: A built-in method for making network requests, returning a promise. •
Axios: A third-party library that simplifies HTTP requests and responses.

2. Handling API Requests:

• Lifecycle Management: Use hooks or lifecycle methods to manage data fetching. •


Error Handling: Implement error management to handle and display issues during
data retrieval.

3. Data Management:

• State Management: Store and manage fetched data within the component’s state. •
Loading States: Display indicators or messages while data is being loaded.
9
CHAPTER – 4

Setting up the Development Environment

To set up a development environment in MERN stack, you'll need to follow these steps:

Step 1: Install Node

Download and install Node.js from the official website: https://nodejs.org/en/

Step 2: Create a New Node Project

Create a new project directory and navigate to it:

• mkdir myProject && cd myProject


• mkdir server && cd server

Initialize a new Node.js project:

• npm init -y

This will create a package.json file.

Step 3: Install Dependencies

Install the required dependencies:

• npm install express cors dotenv

This installs Express, CORS, and dotenv.

Step 4: Create a Node.js Express Server

Create a new file called server.js and add the following code:

const express = require('express');

const app = express();

const cors = require('cors');


const dotenv = require('dotenv');

10
dotenv.config();

app.use(cors());

app.use(express.json());

app.get('/', (req, res) => {

res.send('Hello from MERN stack!');

});

const port = process.env.PORT || 3000;

app.listen(port, () => {

console.log(`Server started on port ${port}`);

});

Step 5: Install Mongoose and MongoDB

Install Mongoose:

• npm install mongoose

Install MongoDB Community Server from the official website :


https://www.mongodb.com/download-center/community

Step 6: Connect to MongoDB database

Create a new file called models/db.js and add the following code:

import mongoose from "mongoose";

const MONGO_URL =
'mongodb://127.0.0.1:27017/EventPlanner?directConnection=true&serverSelectionT
i meoutMS=2000&appName=mongosh+2.2.10'
export const dbConnection = () => {

mongoose

.connect(MONGO_URL)

11
.then(() => {

console.log("Connected to database!");

})

.catch((err) => {

console.log("Some error occured while connecting to database:",

err); });

};

Step 7: Create a React Application

Create a new React app using create-react-app:

• npx create-react-app client

This will create a new React app in a directory called client.

Step 8: Set Up the React Router

Install React Router:

• npm install react-router-dom

Create a new file called client/src/App.js and add the following

code: import React from 'react';

import { BrowserRouter, Route, Switch } from 'react-router-dom';

function App() {
return (

<BrowserRouter>

<Switch>

<Route path="/" exact component={() => <div>Hello from React!</div>} />

12
</Switch>

</BrowserRouter>

);

export default App;

Step 9: Create the React Components

Create new components as needed for your application.

Step 10: Testing the Application

Start the server:

• node server.js

Start the React app:

• cd client
• npm start

Open your web browser and navigate to http://localhost:3000 to see the application in

action. That's it! You now have a basic MERN stack development environment set up.
13
CHAPTER – 5

Building the Back-End with Node.js and Express.js

5.1 Introduction to Node.js

Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine that allows


developers to execute JavaScript code server-side. It is designed for building scalable
network applications and provides a non-blocking, event-driven architecture. Node.js uses an
asynchronous model to handle multiple operations simultaneously without waiting for each
to complete, making it suitable for I/O-heavy tasks. It comes with a package manager called
npm, which provides access to a vast ecosystem of libraries and tools that simplify the
development process.

NPM (Node Package Manager):

• Node.js includes a package manager called npm, which is the largest ecosystem of
open-source libraries in the world.
• npm allows developers to easily manage and share code packages, speeding up the
development process.

5.2 Setting up Express Server

Express.js is a minimal and flexible Node.js web application framework that provides robust
features for building web and mobile applications. To set up an Express server:
• Initialize Project: Begin by creating a new directory for your project and navigate into
it. Run npm init to create a package.json file, which will manage your project's
dependencies and configuration.
• Install Express: Install Express using npm by running npm install express. This
command adds Express to your project's dependencies.
• Create Server File: Create a new JavaScript file (e.g., server.js or app.js) where you
will set up the Express server.
• Setup Basic Server: Import Express and create an instance of an Express application.
Define routes and start the server to listen on a specified port.

5.3 Building Restful APIs

RESTful APIs (Representational State Transfer) are a set of principles for designing
networked applications. They use HTTP requests to manage data in a web application. To
build RESTful APIs with Express:

• Define Routes: Use Express routing methods such as app.get(), app.post(), app.put(),
and app.delete() to handle different HTTP requests.

14
• Implement Handlers: Create route handlers to manage incoming requests, process
data, and send responses. Each handler corresponds to a specific endpoint and HTTP
method.
• Integrate with Database: Connect your API to a database (e.g., MongoDB) to perform
CRUD operations (Create, Read, Update, Delete) on data.
• Test API: Use tools like Postman or cURL to test your API endpoints and ensure they
work as expected.

5.4 Error Handling and Debugging

Error handling and debugging are critical aspects of developing robust and reliable
applications:

• Error Handling:

• Error Middleware: Implement error-handling middleware in Express to catch and


manage errors throughout the application. This middleware typically takes four
arguments: err, req, res, and next.
• Custom Error Messages: Provide meaningful error messages and status codes to
help users and developers understand issues.

• Debugging:

• Console Logging: Use console.log() statements to output information to the console


and track the flow of execution.
• Debugging Tools: Utilize debugging tools and libraries (e.g., node-inspect,
integrated development environment (IDE) debuggers) to step through code and
inspect variables.
• Error Stack Traces: Analyze error stack traces to identify the source of issues and
understand where errors occur.

15
CHAPTER:-6

Getting Started with MongoDB

6.1 Introduction to NoSQL Database

NoSQL databases are designed for flexibility and scalability, capable of handling large
volumes of unstructured or semi-structured data. Unlike traditional relational databases,
NoSQL databases do not rely on a fixed schema, making them ideal for big data applications
and real-time web apps. MongoDB, a widely-used NoSQL database, stores data in BSON
(Binary JSON) format, allowing for nested and hierarchical data structures.

6.2 Setting up MongoDB

MongoDB Atlas is a cloud-based, fully managed database service provided by MongoDB.


Setting it up involves several steps:

1. Create an Account: Sign up at mongodb.com/cloud/atlas.


Create a Cluster:

• Choose a cloud provider (AWS, Azure, Google Cloud).


• Select a region for optimal performance and low latency.
• Configure cluster settings such as instance size and replication options.
2. Configure Security:
• Set up IP whitelisting to restrict access to trusted IP addresses.
• Create database users with appropriate roles and permissions.

3. Connect to Your Cluster:

• Obtain the connection string provided by MongoDB Atlas.


• Use this connection string in your application code to connect to the MongoDB
database.

6.3 CRUD Operations in MongoDB

CRUD operations are the fundamental actions you can perform on data in MongoDB:

• Create: Add new documents to a collection using methods like insertOne() and
insertMany().
• Read: Retrieve documents from a collection using find() and findOne(). You can apply
filters, projections, and sorting to tailor the results.
• Update: Modify existing documents using updateOne(), updateMany(), or replace
documents entirely with replaceOne().
• Delete: Remove documents from a collection using deleteOne() and deleteMany().

16
These operations allow you to manage your data effectively, whether adding new entries,
querying existing data, updating records, or removing obsolete information.

6.4 Mongoose: Object Data Modeling (ODM)

Mongoose is an ODM library for MongoDB and Node.js that provides a schema-based
solution for modeling your application data:

• Installation: Install Mongoose in your Node.js project with npm install mongoose. •
Define a Schema: Create a schema that maps to a MongoDB collection and defines the
structure of documents within that collection.
• Create a Model: Use the schema to create a Mongoose model, which represents a
collection in the database.
• CRUD Operations with Mongoose: Utilize the model to perform CRUD operations.
Mongoose methods (create(), find(), findById(), updateOne(), deleteOne()) simplify
interacting with the database.
• Middleware: Implement middleware functions in Mongoose to perform actions before
or after specific operations, such as data validation or logging.
17
CHAPTER - 7

Connection of Frontend and Backend

7.1 Integrating MongoDB with Express

Integrating MongoDB with an Express.js application involves using Mongoose to manage


data operations. Here’s a brief overview:

1. Set Up Express Server:


o Install Express and create an Express application.
2. Install Mongoose:
o Use npm to install Mongoose, an ODM library for MongoDB.
3. Connect to MongoDB:
o Use Mongoose to connect to your MongoDB database with a connection string.
4. Define Schemas and Models:
Create schemas with Mongoose to define data structure and models for CRUD
o
operations.
5. Create Routes:
o Set up Express routes to handle creating, reading, updating, and deleting
records using Mongoose models.
6. Error Handling:
o Implement error handling and validation for reliable data operations.

7.2 Fetching Data from APIs

Fetching data from APIs involves making HTTP requests from the frontend to retrieve data
from the backend or external services. This can be done using:

• Fetch
API or Axios: Tools to send requests to endpoints and process responses. •
Dynamic Content: Use the retrieved data to update web page content in real-time.

7.3 Handling Form Inputs and Submission

Handling form inputs and submission involves:

1. Creating HTML Forms: Allow users to enter data.


2. Capturing Input with JavaScript: Listen for form submission events and capture
data.
3. Sending Data to Backend: Use HTTP requests to send the data.
4. Processing on Backend: Receive, validate, and process data, often involving database
operations.

18
CHAPTER – 8

Project : Event Planner Web Portfolio

8.1 FrontEnd

React is used to build the front-end of the application. React components are
responsible for rendering the UI and managing user interactions. React can
make API calls to the back-end to fetch or send data.

Components of web page :-

1. Home page –
FIG 8.1

2. Services –

FIG 8.2

19
3. Contact –
FIG – 8.3

8.2 BACKEND

Node.js serves as the runtime environment for running the back-end logic.
Express.js, running on Node.js, handles routing, middleware, and HTTP
requests. It defines the API endpoints that React interacts with.

Server Connectivity –

Fig – 8.4

20
API Routing – 8.3 Database

Fig – 8.5

A database is a structured collection of data organized in a way that allows for


efficient storage, retrieval, and manipulation.

MongoDB stores the application's data. The back-end communicates with


MongoDB to perform CRUD (Create, Read, Update, Delete) operations.

MongoDB is a NoSQL database that stores data in flexible, JSON-like


documents instead of traditional rows and columns.

Database Connectivity –

Fig – 8.6

21
Database Interface -

FIG - 8.7

22
CHAPTER - 9
CONCLUSION

The MERN stack, comprising MongoDB, Express.js, React.js, and Node.js, offers a
comprehensive framework for developing modern web applications. This stack leverages
JavaScript throughout the entire development process, providing a consistent programming
environment for both frontend and backend development.

MongoDB, as a NoSQL database, allows for flexible and scalable data storage, essential for
handling large volumes of unstructured data. Express.js, a minimalist web framework for
Node.js, simplifies the creation of robust APIs and server-side logic. React.js, a powerful
frontend library, enables the development of dynamic and responsive user interfaces through
its component-based architecture and efficient rendering with the virtual DOM. Node.js, a
runtime environment, ensures high performance and scalability for server-side operations due
to its non-blocking, event-driven architecture.

Utilizing the MERN stack, developers can build single-page applications with a seamless user
experience and efficient data handling. The integration of MongoDB with Express.js
facilitates smooth data operations, while React.js enhances the frontend's interactivity and
responsiveness. Node.js ensures that the backend can handle numerous simultaneous
connections efficiently.

The cohesive nature of the MERN stack streamlines the development workflow, allowing
developers to focus on implementing features and optimizing user experience rather than
dealing with compatibility issues between different technologies. Additionally, the
widespread use of JavaScript across all layers of the stack simplifies the learning curve and
improves productivity.

In conclusion, the MERN stack provides a powerful and versatile solution for developing full
stack web applications. Its components work synergistically to deliver high-performance,
scalable, and maintainable applications, making it an excellent choice for modern web
development projects

23
REFERENCES

1. w3schools – https://w3schools.com/
2. Bootstrap – https://getbootstrap.com/
3. React Installation - https://react.dev/
4. Node Installation - https://nodejs.org/en
5. ExpressJS - https://www.postman.com/
6. MongoDB - https://www.mongodb.com/
24

You might also like