Yuvraj report
Yuvraj report
Seminar Report on
“MERN Stack Development”
By
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.
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
handling………………………………………………….6
vi
6.4 Mongoose: Object Data Modeling (ODM)………………………………….17 7.
FrontEnd……………………………………………………………………..19 8.2
BackEnd……………………………………………………………………..20 8.3
Database……………………………………………………………………..20
9.CONCLUSION…………………………………………………...……………....23
REFERENCES……………………………………………………………….....24
vii
LIST OF FIGURES
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.
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
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.
FIG :1.1
• 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.
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
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.
FIG 2.1
3
2.1.2 Common HTML Elements
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.
4
Properties define the style rules applied to elements:
Fig 2.2
5
2.2.4 CSS Frameworks: Bootstrap
• Responsive Design: Bootstrap's grid system and responsive design principles allow
websites to adapt to different screen sizes and devices seamlessly.
• 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.
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.
7
CHAPTER – 3
Frontend framework: React.js
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:
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:
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:
• Fetch API: A built-in method for making network requests, returning a promise. •
Axios: A third-party library that simplifies HTTP requests and responses.
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
To set up a development environment in MERN stack, you'll need to follow these steps:
• npm init -y
Create a new file called server.js and add the following code:
10
dotenv.config();
app.use(cors());
app.use(express.json());
});
app.listen(port, () => {
});
Install Mongoose:
Create a new file called models/db.js and add the following code:
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) => {
err); });
};
function App() {
return (
<BrowserRouter>
<Switch>
12
</Switch>
</BrowserRouter>
);
• node server.js
• 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
• 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.
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.
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.
Error handling and debugging are critical aspects of developing robust and reliable
applications:
• Error Handling:
• Debugging:
15
CHAPTER:-6
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.
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.
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
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.
18
CHAPTER – 8
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.
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
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