GOVERMENT POLYTECHNIC
DAMAN
MINI PROJECT
ON
“BUILDING A SIMPLE BLOG WITH MONGODB AND ANGULAR”
OF
“NO-SQL”
DIPLOMA SEMESTER 6 (COMPUTER ENGINEERING)
SUBMITTED BY:
RAJESH TIWARY (216580307025)
GUIDED BY:
MR. VANDANBABU T.
(LECTURER)
DEPARTMENT OF COMPUTER ENGINEERING
(ACADEMIC YEAR: 2024-25)
INDEX
Sr.No. Content Page NO.
1 • Introduction to 01
Building a
Simple Blog
2 Introduction to MongoDB 01-02
• Features
• Advantages
and
Disadvantages
3 • Installation of 03
MongoDB
• Applications
ofMongoDB
4 Introduction to Node.js 04
• Features
5 • Building a Blog 05
Using MongoDB and
Node.js
6 • Deploying the Blog 06-07
Application
• Database Connection
7 • Blog Application 07-10
Code and Output
8 • Conclusion 10
INTRODUCTION TO BUILDING A SIMPLE BLOG
Building a blog from scratch can be a rewarding and enriching experience, allowing you to share your
thoughts, ideas, and expertise with the world. In this introductory section, we will explore the
foundations of creating a simple blog using the powerful combination of MongoDB, a popular NoSQL
database, and Node.js, a robust JavaScript runtime environment. By the end of this journey, you'll have
the knowledge and skills to design and develop your own dynamic blog application, empowering you
to effectively communicate and engage with your audience online
INTRODUCTION TO MONGODB
MongoDB is a popular open-source NoSQL database management system that uses a document-
oriented data model. It stores data in flexible, JSON-like documents called BSON (Binary JSON) and
is designed to handle large volumes of unstructured or semi-structured data. MongoDB is schema-
flexible, allowing for dynamic and agile development, and provides features such as high availability,
horizontal scalability through sharding, and a powerful query language with rich indexing and
aggregation capabilities. It is widely used in modern web and mobile applications, IoT (Internet of
Things) platforms, and real-time analytics systems.
Here are some key aspects of MongoDB:
1. Document-Oriented: MongoDB stores data in flexible, JSON-like documents called BSON (Binary
JSON) documents. Each document can have its own unique structure, allowing for more dynamic and
schema-less data storage compared to traditional relational databases.
2. NoSQL Database: MongoDB is part of the NoSQL family of databases, which means it diverges
from the traditional SQL (Structured Query Language) approach used in relational databases like
MySQL or PostgreSQL. NoSQL databases are designed to be more flexible and scalable for modern
applications that deal with diverse and rapidly changing data.
3. Features:
• Schema Flexibility: MongoDB does not enforce a strict schema like SQL databases. This
allows developers to easily modify the structure of documents without downtime or
migrations.
• High Availability: MongoDB supports replica sets, which provide automatic failover and
data redundancy to ensure high availability.
• Horizontal Scalability: MongoDB can scale horizontally by sharding, distributing data
across multiple servers to handle large amounts of data and traffic.
• Rich Query Language: MongoDB provides a powerful query language that supports
filtering, sorting, and aggregation operations.
• Indexing: MongoDB supports various types of indexes to optimize query performance,
including single-field, compound, geospatial, and text indexes.
• Aggregation Framework: MongoDB includes a versatile aggregation framework for
performing complex data processing tasks, such as grouping, sorting, and transforming data.
01
4. Components:
• Database: A MongoDB deployment can contain multiple databases, each of which contains
collections.
• Collection: A collection is a grouping of MongoDB documents. It is analogous to a table in a
relational database.
• Document: A document is a BSON object that contains key-value pairs of data. It corresponds
to a record or row in a relational database.
5. Use Cases:
• MongoDB is used in various applications and industries, including content management
systems, e-commerce platforms, real-time analytics, IoT (Internet of Things) applications, and
mobile app backends.
• Its flexible schema and scalability make it particularly suitable for agile development
environments and applications that need to handle large and dynamic datasets.
Advantages Disadvantages
Flexible Schema: MongoDB allows for dynamic Memory Consumption: MongoDB can consume
and flexible schema design, enabling easy more memory compared to traditional SQL
modifications to the data structure without databases due to its indexing and document storage
downtime or migrations. model.
Scalability: MongoDB supports horizontal No ACID Transactions: MongoDB lacks full
scalability through sharding, distributing data support for ACID (Atomicity, Consistency,
across multiple servers, making it suitable for Isolation, Durability) transactions across multiple
large-scale applications with growing data needs. documents or collections.
High Performance: It provides high read and Complexity in Data Modeling: Although flexible,
write throughput due to its efficient indexing and designing effective data models in MongoDB can be
query optimization capabilities. challenging, especially for applications with
complex relationships.
Document-Oriented: MongoDB's document- Limited Join Operations: MongoDB does not
oriented model aligns well with object-oriented support joins like relational databases, requiring
programming, making it easier for developers to denormalization of data and careful schema design.
work with data.
02
12
INSTALLATION OF MONGODB:
To install MongoDB, you'll typically follow these steps based on your operating system. Here's a
general guide for installing MongoDB on popular platforms like Windows:
Windows Installation Steps:
1. Download MongoDB:
• Go to the MongoDB download page: MongoDB Download Center
• Select the appropriate version and edition (Community Server) for your Windows
system.
• Click the "Download" button to get the installer.
2. Run the Installer:
• Once the download completes, locate the downloaded installer file (e.g., mongodb-
installer-version-number.msi).
• Double-click the installer to start the installation process.
3. Setup MongoDB:
• Follow the installation wizard steps.
• Choose the "Complete" setup type for a typical installation.
• Optionally, you can customize the installation path, but the default path is
recommended.
4. Start MongoDB Service:
• MongoDB will be installed as a Windows service.
• After installation, MongoDB service should start automatically. If not, you can start it
manually using Windows Services.
APPLICATIONS OF MONGODB:
1. Content Management and Delivery:
• MongoDB is well-suited for content management systems where content is diverse and
schema-less, such as blogs, news websites, and e-commerce platforms. It can
efficiently handle large volumes of unstructured data like text, images, and metadata.
2. Real-Time Analytics and Reporting:
• MongoDB's ability to handle high-volume, time-series data makes it ideal for real-time
analytics and reporting applications. It can store and analyse large datasets generated
by IoT devices, sensors, and transaction logs, enabling businesses to derive actionable
insights quickly.
3. Mobile App Backends:
• MongoDB is commonly used as a backend database for mobile applications due to its
flexibility and scalability. It can store and retrieve data in a format that aligns well with
the JSON-based data models used in mobile development.
4. IoT (Internet of Things) and Sensor Data Management:
• MongoDB's ability to handle semi-structured and rapidly evolving data makes it
suitable for managing IoT and sensor data. It can store and process data from a wide
range of devices, enabling real-time monitoring and analysis.
5. Personalization and Recommendation Systems:
• MongoDB's document-oriented data model allows for the storage of complex user
profiles and preferences. It is used in recommendation engines to deliver personalized
content, products, and services based on user behaviour and interests.
303
INTRODUCTION TO NODE.JS
Node.js is a powerful JavaScript runtime built on Chrome's V8 JavaScript engine. It enables developers to
execute JavaScript code outside of a web browser, making it possible to build server-side applications using
JavaScript. Node.js has gained significant popularity due to its event-driven, non-blocking I/O model,
which allows for efficient handling of concurrent connections and real-time data processing. Let's explore
its features, advantages, and disadvantages.
Here are some key features and concepts of Node.JS:
1. Asynchronous and Event-Driven: Node.js uses an event-driven, non-blocking I/O model,
allowing it to handle concurrent connections efficiently. This makes it well-suited for building
real-time applications such as chat applications, streaming services, and collaborative tools.
2. Single-Threaded, Non-Blocking: Node.js employs a single-threaded event loop architecture,
where a single thread handles multiple client requests asynchronously. This architecture
maximizes resource utilization and minimizes overhead, making Node.js highly scalable and
efficient.
3. NPM (Node Package Manager): Node.js comes with NPM, a powerful package manager
that allows developers to easily install, manage, and share reusable code packages (modules).
NPM provides access to a vast ecosystem of third-party libraries and frameworks, enabling
rapid development and code reuse.
4. Cross-Platform Compatibility: Node.js runs on multiple platforms, including Windows,
macOS, and Linux, making it a versatile choice for building applications that can be deployed
across different operating systems.
04
2
BUILDING A SIMPLE BLOG USING MONGODB AND Node.JS
1. Set Up Development Environment:
Install Node.js: Download and install Node.js from the official website ( https://nodejs.org/ ).
Install MongoDB: Download and install MongoDB from the official website
(https://www.mongodb.com/try/download/community ).
2. Initialize Node.js Project:
Create a new directory for your project.
Open a terminal or command prompt and navigate to the project directory.
Run ‘npm init -y’ to initialize a new Node.js project with default settings.
3. Install Dependencies:
Install required Node.js packages using npm. You will need packages like Express.js (for backend framework),
Mongoose (for MongoDB integration), and any other packages for authentication, validation, etc.
Example: ‘npm install express mongoose’
4. Set Up Express.js Server:
Create a new JavaScript file (e.g., server.js) in your project directory.
Require Express.js and create an instance of the Express application.
Define routes for handling HTTP requests, such as GET, POST, PUT, DELETE for blog posts, user
authentication, etc.
Start the Express server and listen for incoming requests.
Example:
const express = require('express');
const app = express();
// Define routes
app.get('/', (req, res) => {
res.send('Hello World!');
});
// Start server
const PORT = process.env.PORT || 8081;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});
05
5
5. Set Up MongoDB Connection
Create a db.js file to establish a connection to MongoDB using Mongoose:
const mongoose = require('mongoose');
const connectDB = async () => {
try {
mongoose.set('strictQuery', false);
const conn = await mongoose.connect(process.env.MONGODB_URI);
console.log(`Database Connected: ${conn.connection.host}`);
} catch (error) {
console.log(error);
}
}
module.exports = connectDB;
6.Implement Frontend:
Create CSS, and JavaScript files for the frontend interface.
<div class="author">
<h1 class="author__heading">Hi, I am Rajesh Tiwary.</h1>
<p class="author__body">Web developer and content creator.</p>
</div>
<img src="/img/hero-image.webp" alt="person looking out through window" class="hero-image"
width="981" height="528">
<section class="articles">
<h2 class="articles__heading">Latest Posts</h2>
<ul class="article-ul">
<% data.forEach(post => { %>
<li>
<a href="/post/<%= post._id %>">
<span><%= post.title %></span>
<span class="article-list__date"><%= post.createdAt.toDateString() %></span>
</a>
</li>
<% }) %>
</ul>
<% if (nextPage !== null) { %>
<a href="/?page=<%= nextPage %>" class="pagination">< View Older Posts</a>
<% } %>
</section>
06
7. Set Up Server: Create a configure routes and start the server:
.env
PORT=8081
JWT_SECRET=HELLOWORLD
MONGODB_URI=mongodb+srv://rajesh_tiwary:rajesh_tiwary@cluster0.mvqmxbs.mongodb.net/
blog54354
8. Run Your Application:
Start your Node.js server by running node server.js in the terminal.
Open your web browser and navigate to http://localhost:8081 (or the specified port) to view your simple blog
application.
BLOG APPLICATION OUTPUT
OUTPUT:
7
07
08
09
conclusion
In conclusion, the project of building a simple blog using MongoDB and Node.js has been successfully
completed, providing a solid foundation for a functional and scalable blogging platform. Throughout the
development process, several key aspects were addressed, resulting in a fully functional application with
essential features for blog management.
10