Final Year Report (P)
Final Year Report (P)
SESSION (2023-2024)
PROJECT REPORT
ON
“MERN BLOG”
SUBMITTED
IN PARTIAL FULFILLMENT REQUIREMENT FOR DEGREE
OF
BACHELOR OF TECHNOLOGY
IN
COMPUTER SCIENCE & ENGINEERING
UNDER THE GUIDENCE OF
______________ _____________
(Project Guide) (HOD)
________________
(Dean Academics)
2
ACKNOWLEDGMENT
I would like to place on record my deep sense of gratitude to Er. DIPTI RANJAN
TIWARI Dept. of Computer Science and Engineering Lucknow Institute of
Technology, Lucknow, India for her generous guidance, help and useful suggestions.
PRITY KUMARI(2003620100034)
3
DECLARATION
I hereby declare that this project work entitled “MERN BLOG” has been prepared by
us during the year 2023-24 under the guidance of ER. DIPTI RANJAN TIWARI,
Department of COMPUTER SCIENCE AND ENGINEERING, LUCKNOW
INSTITUTE OF TECHNOLOGY, LUCKNOW in the partial fulfillment of B. Tech
degree presented by the college.
I also declare that this project is the outcome of our my effort, that it has not been
submitted to any other university for the award of any degree
4
ABSTRACT
This project involves creating a blog website using the MERN stack (MongoDB,
Express.js, React.js, Node.js). The website allows users to read, create, edit, and
delete blog posts. MongoDB stores user data and posts, Express.js handles the
backend, React.js builds a responsive frontend, and Node.js runs the server.
Through this blog website project, the efficacy of the MERN stack in building a full-
fledged web application is showcased, highlighting its benefits in terms of
performance, scalability, and maintainability. This project serves as a comprehensive
example for developers looking to harness the power of the MERN stack in their web
development endeavors.
5
TABLE OF CONTENTS
1.Intoduction………………………………………………………………7-11
2.Project Overview………………………………………………………12-15
3.Technologies…………………………………………………………...16-24
4.Architecture………………………………………………………………25
4.1 Sign in page…………………………………………………………25-27
4.2 Log in page…………………………………………………………..27-28
4.3 Forgot password……………………………………………………..29-31
5.Features………………………………………………………………...32-34
6.Development process…………………………………………………35-39
7.Challenges/Solutions………………………………………………….40-42
8.Goals………………………………………………...………………….43-46
9.Conclusion……………………………………………………………...47-49
10.References………………………………………………………………..50
6
INTRODUCTION
1. Background and Motivation:
The rise of the internet and digital technologies has revolutionized how we
communicate, share information, and express our ideas. Blogging has become a
powerful medium for individuals and organizations to disseminate information, share
personal experiences, and engage with a global audience. With the advent of
modern web development technologies, building dynamic and interactive blog
websites has become more accessible and efficient.
The MERN stack, which includes MongoDB, Express.js, React.js, and Node.js, is a
popular technology stack that enables developers to create full-stack web
applications. This project aims to leverage the MERN stack to develop a robust,
scalable, and user-friendly blog website. By utilizing the strengths of each
component in the MERN stack, this project will demonstrate the effectiveness of
these technologies in building a comprehensive web application.
2. Objectives:
The primary objectives of the MERN Blog Website project are:
• To develop a full-stack blog application that allows users to read, create, edit,
and delete blog posts.
• To create a responsive and intuitive user interface that enhances the user
experience.
The MERN Blog Website project will include the following features:
CRUD Operations for Blog Posts: Allowing users to perform Create, Read,
Update, and Delete operations on blog posts.
Responsive Design: Ensuring that the website is fully responsive and provides an
optimal viewing experience across different devices, including desktops, tablets, and
smartphones. 8
Comment System: Enabling users to comment on blog posts and engage in
discussions.
Search and Filtering: Providing search and filtering functionalities to help users find
specific blog posts based on keywords, categories, or tags.
User Profiles: Allowing users to manage their profiles, view their published posts,
and update their personal information.
• Node.js: By using JavaScript on both the client and server sides, Node.js
streamlines the development process and allows for code reuse. Its non-
blocking, event-driven architecture ensures high performance and scalability,
making it ideal for real-time web applications.
9
6. Development Methodology
The development of the MERN Blog Website will follow an agile methodology,
emphasizing iterative development, collaboration, and continuous improvement. The
project will be divided into multiple phases, each focusing on specific aspects of the
application:
10
7. Expected Outcomes
Upon completion of the MERN Blog Website project, the following outcomes are
expected:
• A fully functional blog website that demonstrates the capabilities of the MERN
stack in building a dynamic and scalable web application.
11
PROJECT OVERVIEW
1. Introduction
The MERN Blog application is a full-stack web application built using the MERN
stack, which comprises MongoDB, Express.js, React.js, and Node.js. This
application serves as a platform for users to create, read, update, and delete blog
posts. It also includes features for user authentication and authorization, allowing
users to manage their content securely.
2. Objectives
- Develop a scalable and maintainable blog platform** that allows users to perform
CRUD (Create, Read, Update, Delete) operations on blog posts.
- Implement user authentication and authorization** to secure user data and manage
user-specific content.
- Ensure a responsive and user-friendly interface** using modern front-end
technologies.
3. Technology Stack
- MongoDB: A NoSQL database used to store blog posts and user data.
- Express.js: A web application framework for Node.js used to build the server-side
logic and APIs.
- React.js: A front-end library used to build the user interface.
- Node.js: A JavaScript runtime environment used to run the server-side code.
4. Features
- User Registration and Login: Users can sign up and log in to access their accounts.
- Authentication and Authorization: Secure access to user-specific content using
JSON Web Tokens (JWT).
- CRUD Operations for Blog Posts:
- Create: Users can create new blog posts.
- Read: Users can view all blog posts or specific posts. 12
- Update: Users can edit their own blog posts.
- Delete: Users can delete their own blog posts.
- Rich Text Editor: Users can write and format their blog posts using a rich text
editor.
- Comment System: Users can comment on blog posts.
- Responsive Design: The application is designed to work on various devices,
including desktops, tablets, and smartphones.
5. Architecture
The MERN Blog application follows a client-server architecture.
- Front-End:
- Built with React.js.
- Utilizes Redux for state management.
- Communicates with the backend via RESTful APIs.
- React Router is used for client-side routing.
- Back-End:
- Built with Node.js and Express.js.
- Uses MongoDB as the database.
- Implements RESTful APIs for communication with the front end.
- Handles user authentication and authorization.
6. Database Schema
The MongoDB database is designed with two primary collections:
- Users:
- _id (ObjectId)
- username (String)
- email (String)
- password (String, hashed) 13
- profilePicture (String, URL to image)
- Posts:
- _id (ObjectId)
- title (String)
- content (String)
- author (ObjectId, references Users)
- comments (Array of comment objects)
- createdAt (Date)
- updatedAt (Date)
8. Development Workflow
- Version Control: Git is used for version control, with GitHub as the repository host.
- Code Reviews: Regular code reviews are conducted to ensure code quality and
consistency.
- Testing: Unit and integration tests are written using Jest and other testing libraries.
- Continuous Integration: CI/CD pipelines are set up using GitHub Actions to
automate testing and deployment.
9. Deployment
- Front-End: Deployed on a static site hosting service like Netlify or Vercel.
- Back-End: Deployed on cloud services like Heroku or AWS.
- Database: MongoDB Atlas is used for the cloud database.
14
10. Future Enhancements
- User Profiles: Allow users to create and edit their profiles.
- Tags and Categories: Implement a system for tagging and categorizing blog posts.
- Likes and Shares: Enable users to like and share blog posts.
- Search Functionality: Implement a search feature to find blog posts by keywords.
- Notifications: Add a notification system for new comments and likes.
15
TECHNOLOGIES USED
Technologies Used in a MERN Blog Website
1. MongoDB
- Database A NoSQL database used to store and manage the blog posts, user data,
and other related information. Its flexible schema and scalability make it ideal for
handling the dynamic data of a blogging platform.
2. Express.js
- Web Application Framework: Used to build the back-end server and handle routing,
middleware, and RESTful APIs. Express.js simplifies the process of creating a robust
and scalable server-side application.
3. React.js
- Front-End Library: A JavaScript library for building the user interface. React's
component-based architecture and virtual DOM provide a highly responsive and
dynamic user experience.
- State Management: Tools like Redux or Context API are often used alongside
React for efficient state management.
4. Node.js
- **Runtime Environment**: Enables the execution of JavaScript on the server-side.
Node.js's non-blocking, event-driven architecture ensures high performance and
scalability.
- Authentication and Authorization: - JWT (JSON Web Tokens): Used for secure
user authentication and session management. 16
- bcrypt: A library for hashing passwords to enhance security.
- Routing:
- React Router: Facilitates client-side routing, enabling single-page application
(SPA) functionality.
- API Development:
- RESTful APIs: Developed using Express.js to handle CRUD operations for blog
posts and user management.
- Database Management:
- Mongoose: An Object Data Modeling (ODM) library for MongoDB, which provides
a schema-based solution to model application data.
- Development Tools:
- Webpack: A module bundler used to compile JavaScript modules and other
assets for deployment.
- Babel: A JavaScript compiler that converts ES6+ code into backwards-compatible
JavaScript.
- Testing:
- Jest: A testing framework used for unit and integration tests in both the front end
and back end.
- Mocha/Chai: Alternative testing frameworks for back-end testing.
- Deployment:
- Heroku: A cloud platform for deploying and managing the back-end server.
- Netlify/Vercel: Platforms for deploying the front-end React application.
- MongoDB Atlas: A cloud-based database service for deploying and managing the
MongoDB database.
18
Source code of application system:
FRONTEND - App.js
return (
<Router>
<div className="App"> 19
<Routes>
<Route path="/" element={<LayoutsWithHeader />}>
</Route>
</Routes>
</div>
</Router>
);
22
BACKEND – Server.js
dotenv.config({
path: './Config/config.env'
})
connectDatabase()
app.use(express.json())
app.use(cors())
app.use("/",IndexRoute)
app.use(customErrorHandler)
})
server.close(()=>process.exit(1))
})
24
ARCHITECTURE
Sign in page –
A sign-in page for a MERN (MongoDB, Express.js, React, Node.js) blog website is a
crucial component that allows users to log in to their accounts. Here's an explanation
of the main aspects and functionality typically involved.
The frontend part of the sign-in page is built using React, providing an interactive
and dynamic user experience.
1. Form Layout:
o Username/Email Field: An input field where users enter their
username or email.
o Password Field: An input field where users enter their password. This
field should be of type password to mask the input.
o Submit Button: A button to submit the form and trigger the login
process.
25
2. State Management:
o React's useState hook is commonly used to manage the form inputs'
state.
o Validation states (e.g., error messages for incorrect credentials) are
also managed here.
3. Form Handling:
o An onSubmit function that handles the form submission. It usually
prevents the default form submission behavior and instead, sends an
HTTP request to the backend.
1. Route Handling:
o An Express route for handling login requests, typically POST /login.
o This route will receive the login credentials from the frontend.
2. Authentication Logic:
o Validation: Ensure that the received credentials are not empty and are
in the correct format.
o Database Query: Query the MongoDB database to find a user with the
provided username or email.
3. Session Generation:
o Password Verification: Compare the provided password with the
stored hashed password using a library like bcrypt.
4. Token Generation:
o If the credentials are correct, generate a session or a JWT (JSON Web
Token) to authenticate the user in subsequent requests.
o Send the session ID or token back to the frontend. 26
5. Response Handling:
o Send appropriate responses back to the frontend:
1. Success: A success message and user data (excluding
sensitive information).
2. Failure: Error messages indicating what went wrong (e.g.,
invalid credentials).
Log in page –
1.Login Endpoint: Create an endpoint that accepts user credentials (email and
password) via a POST request.
3. Password Validation: Compare the submitted password with the hashed password
stored in the database. 27
4. Token Generation: If the credentials are valid, generate a JSON Web Token
(JWT) to authenticate the user.
5. Response: Send the JWT back to the client for use in subsequent requests.
Frontend (React)
1. Login Form: Create a login form that captures the user's email and password.
2. Form Submission: When the form is submitted, send the credentials to the
backend login endpoint using an HTTP request (e.g., via Axios).
3. Token Storage: On successful login, store the JWT in local storage or cookies.
4. State Management: Update the application state to reflect that the user is
authenticated.
5. Protected Routes: Use React Router to protect certain routes, allowing access
only to authenticated users based on the presence of a valid JWT.
28
Forgot page –
- Endpoint: Create an endpoint where users can submit their email address to
request a password reset.
- Token Generation: Generate a unique, time-limited reset token and store it in the
database, associated with the user's account.
- Email Sending: Send an email to the user containing a link to reset their
password. This link includes the reset token.
29
2. Reset Password:
- Endpoint: Create an endpoint where users can submit a new password along with
their reset token.
- Token Verification: Validate the reset token to ensure it is correct and has not
expired.
- Password Update: Hash the new password and update the user's record in the
database.
Frontend (React)
- Create a form where users can enter their email address to request a password
reset.
- This form is accessed via a link sent to their email, which includes the reset token.
- Handle form submission to send the new password and reset token to the backend
endpoint.
30
- Backend:
- Provides endpoints for requesting a password reset and for setting a new
password.
- Handles token generation, storage, email sending, and password update.
- Frontend:
- Provides forms for requesting a password reset and for entering a new password.
31
FEATURES
A MERN (MongoDB, Express, React, Node.js) blog website can offer a variety of
features to enhance user experience and provide comprehensive blogging
functionality. Here are some key features typically included:
2. User Profiles
4. Content Organization
• Categories and Tags: Organize posts into categories and tags for easier
navigation.
• Search Functionality: Allow users to search for posts by keywords.
6. Notifications
• SEO Optimization: Meta tags, keywords, and descriptions for better search
engine visibility.
• Social Media Sharing: Easy sharing of posts on social media platforms.
8. Admin Dashboard
• User Management: Admins can manage users, their roles, and permissions.
• Content Moderation: Admins can review and moderate posts and
comments.
• Analytics: View statistics about website traffic, user activity, and post
performance.
9. Responsive Design
• Mobile-Friendly: Ensure the blog is accessible and looks good on all devices.
33
11. Integration
• Third-Party APIs: Integrate with other services like email providers, analytics,
and social media.
• Markdown Support: Allow users to write posts in Markdown.
34
DEVELOPMENT PROCESS
• Create detailed user stories to capture the requirements from different user
perspectives, such as:
o "As a visitor, I want to read blog posts."
o "As a user, I want to register an account."
o "As an author, I want to create and manage my blog posts."
o "As an admin, I want to manage users and content."
• Design wireframes for each page, showing the layout and placement of
elements.
• Create high-fidelity mockups to visualize the final design.
Initialize Repositories:
Project Initialization:
Database Setup:
API Development:
Authentication:
CRUD Operations:
• Posts: Endpoints for creating, reading, updating, and deleting blog posts.
• Comments: Endpoints for adding, editing, and deleting comments on posts.
Middleware:
Project Initialization:
Component Structure:
• Plan the component hierarchy and break down the UI into reusable
components such as:
o App: Main component.
o Navbar: Navigation bar.
o Footer: Footer of the site.
o Login, Register: Authentication forms.
o BlogPost, PostList, PostDetail: Components to display blog posts.
o Profile: User profile page.
36
State Management:
Routing:
UI Development:
API Integration:
Form Handling:
5. Security Measures
Password Encryption:
JWT Authentication:
• Use JSON Web Tokens for secure authentication and session management.
• Store JWTs in secure HTTP-only cookies or local storage.
Input Validation:
• Validate and sanitize all user inputs to prevent SQL injection, XSS, and other
attacks.
HTTPS:
37
6. Testing and Debugging
Backend Testing:
• Write unit tests for individual functions and API endpoints using frameworks
like Mocha or Jest.
• Implement integration tests to ensure different parts of the application work
together.
Frontend Testing:
• Write unit tests for React components using Jest and React Testing Library.
• Use tools like Enzyme for component testing.
End-to-End Testing:
• Use tools like Cypress to test the entire application flow from the user’s
perspective.
Debugging:
7. Deployment
Backend Deployment:
Frontend Deployment:
• Deploy the React application to a static hosting service like Netlify, Vercel, or
AWS S3.
• Optimize the frontend for production using build tools.
• Automate build and deployment processes using CI/CD tools like GitHub
Actions, Travis CI, or Jenkins.
38
8. Monitoring and Maintenance
Monitoring:
Feature Enhancements:
• Continuously improve the blog by adding new features and enhancing existing
ones based on user feedback and analytics.
9. Documentation
API Documentation:
User Documentation:
Developer Documentation:
User Feedback:
• Collect feedback from users through surveys, feedback forms, and direct
communication.
• Analyze feedback to understand user needs and pain points.
Iteration:
39
CHALLENGES AND ITS SOLUTIONS
Building a MERN (MongoDB, Express.js, React.js, Node.js) blog website involves
various challenges, spanning from setting up the development environment to
deployment and scaling. Let's delve into each challenge and its detailed solutions:
o Solution: Adopt React Router for declarative routing within your React
application. Define routes for different views/pages of the blog, such as
home, individual blog posts, and user authentication. For state
management, consider using libraries like Redux or React Context API.
Centralize application state in a Redux store or Context API provider,
making it accessible across components. Dispatch actions to update
state based on user interactions or backend data.
6. Performance Optimization:
o Challenge: Ensuring optimal performance of the blog website is crucial
for providing a seamless user experience, including fast page load
times and responsive UI.
41
7. Security Concerns:
o Challenge: Protecting the blog website against common security
threats such as cross-site scripting (XSS), cross-site request forgery
(CSRF), and injection attacks is essential to safeguard user data and
maintain the integrity of the application.
42
GOALS
The goals of a MERN (MongoDB, Express.js, React.js, Node.js) blog website revolve
around providing a seamless and engaging user experience, while also ensuring
efficient content management and scalability. Here's a detailed exploration of the
goals:
2. Content Management:
o Easy Content Creation: Provide a user-friendly interface for authors
to create, edit, and publish blog posts effortlessly. Implement a rich text
editor or markdown support to facilitate content creation. 43
o Content Organization: Enable categorization and tagging of blog
posts to organize content effectively and make it easier for users to
discover relevant articles.
44
4. Community Building and Engagement:
45
o Affiliate Marketing: Partner with affiliate programs and promote
relevant products or services through affiliate links within blog posts,
earning commissions for referrals and conversions.
Overall, the goals of a MERN blog website revolve around delivering a seamless
user experience, facilitating efficient content management, ensuring scalability and
performance, fostering community engagement, and achieving monetization
objectives. By prioritizing these goals and implementing appropriate strategies and
features, the blog can effectively serve its audience and meet the needs of both
users and stakeholders.
46
CONCLUSION
Building a MERN (MongoDB, Express.js, React.js, Node.js) blog website is a journey
that encompasses numerous challenges, strategies, and objectives. As we draw to a
conclusion, it's essential to reflect on the holistic process and the implications of
creating such a platform.
Throughout the development journey, the primary goal is to craft a blog website that
not only delivers valuable content but also provides an exceptional user experience.
From the initial setup of the development environment to the deployment of the final
product, every step is guided by the overarching mission of creating a seamless and
engaging platform for users.
One of the critical aspects of building a MERN blog website is ensuring a robust and
intuitive user experience. This involves designing a user-friendly interface, optimizing
performance for fast loading times, and implementing responsive design principles to
accommodate users across various devices and screen sizes. By prioritizing UX, we
aim to create an environment where users can effortlessly navigate through content,
interact with features, and feel immersed in the blog's community.
47
Content creation and management are central to the mission of a MERN blog.
Authors should be empowered with tools and workflows that make it easy to create,
edit, and publish blog posts. Features such as categorization, tagging, and search
functionality enhance content discoverability and make it easier for users to find
relevant articles. Additionally, moderation tools help maintain the quality and integrity
of user-generated content, fostering a positive and constructive community
atmosphere.
Community building and engagement are central to the ethos of the MERN blog. By
fostering interaction, collaboration, and connection among users, we aim to cultivate
a vibrant and supportive community around the blog's content. Features such as
comments sections, social sharing, and user-generated content contribute to a
sense of belonging and ownership among users, driving engagement and
participation.
48
In conclusion, building a MERN blog website is about more than just creating a
platform for publishing content—it's about crafting an immersive and inclusive online
community where individuals can connect, learn, and share their passions. By
embracing the challenges and opportunities inherent in this process, we aim to
create a blog that not only informs and entertains but also inspires and empowers its
audience. Through thoughtful design, strategic planning, and ongoing iteration, we
strive to build a MERN blog website that makes a meaningful and lasting impact in
its niche.
49
References:
MongoDB Documentation
React
50