You are on page 1of 8

Department of Computer Engineering

Course Name & Code: Web Technology (310252)

Case Study (Unit-III)

Title: Develop server-side code for blogging application.

Introduction:
In the digital age, blogging has become a ubiquitous form of expression, information
sharing, and communication. Whether it's personal journals, professional insights, or
niche interests, blogs offer individuals and organizations a platform to voice their
thoughts and engage with a wider audience.
A server-side blogging application serves as the backbone for managing this content
efficiently and securely. It provides users with the tools they need to compose, edit,
and publish blog posts, while also offering features for organizing, searching, and
interacting with published content.

Hardware and Software Requirements:

1) Operating System: window 11/Linux

2) Database: MongoDB

3) Language: JavaScript

4) Libraries and Frameworks: Node.js and npm, Express.js, Mongoos

5) Development Tools: VS Code


Implementation:
To develop a server-side code for a blogging application using Node.js with Express
framework and MongoDB as the database in Visual Studio Code (VS Code), follow
these steps:

Step 1: Set up your project

. Open Visual Studio Code.


. Create a new folder for your project.
. Open this folder in VS Code.

Step 2: Initialize your Node.js project

. Open the terminal in VS Code (View > Terminal).


. Run the following command to initialize a new Node.js project:

npm init -y
This command creates a package.json file with default settings.

Step 3: Install required packages

. Install Express.js for creating the server:


npm install body-parser

Install Mongoose for interacting with MongoDB:


npm install mongoose

Install body-parser middleware for parsing incoming request bodies:


npm install body-parser
Step 4: Create your server-side code

Create a JavaScript file (e.g., app.js) in your project folder and write your server-side
code. Here's a simple example:

// Import required modules

const express = require('express');

const mongoose = require('mongoose');

const bodyParser = require('body-parser');

// Initialize Express app

const app = express();

app.use(bodyParser.json());

// Connect to MongoDB

mongoose.connect('mongodb://localhost:27017/blog', { useNewUrlParser: true,


useUnifiedTopology: true })

.then(() => console.log('Connected to MongoDB'))

.catch(err => console.error('Failed to connect to MongoDB', err));

// Define mongoose schema for BlogPost

const blogPostSchema = new mongoose.Schema({

title: String,

content: String,
author: String,

createdAt: { type: Date, default: Date.now },

tags: [String]

});

// Define mongoose model for BlogPost

const BlogPost = mongoose.model('BlogPost', blogPostSchema);

// API endpoints

// GET all blog posts

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

try {

const posts = await BlogPost.find().sort('-createdAt');

res.json(posts);

} catch (err) {

res.status(500).json({ message: err.message });

});

// POST a new blog post

app.post('/api/posts', async (req, res) => {

const post = new BlogPost({


title:

req.body.title,

content: req.body.content,

author: req.body.author,

tags: req.body.tags

});

try {

const newPost = await post.save();

res.status(201).json(newPost);

} catch (err) {

res.status(400).json({ message: err.message });

});

// Start the server

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

app.listen(PORT, () => console.log(`Server started on port ${PORT}`));


Step 5: Run your server

. Save your app.js file.


.
. Open the terminal in VS Code.
. Run the following command to start your server:

node app.js

Your server should now be running and accessible at http://localhost:3000


Advantages:
 Customization
 Scalability
 Security
 Performance
 Integration
 SEO Friendliness
 Offline Access
 Control over Data
 Community Support

Disadvantages:
 Complexity
 Cost:
 Resource Intensive
 Deployment and Maintenance
 Performance Limitations
 Scalability Challenges:
 Vendor Lock-in
 Security Vulnerabilities

Conclusion:
In conclusion, server-side blogging applications offer a robust and flexible platform
for creating, managing, and sharing blog content. While they come with certain
disadvantages, such as complexity, cost, and scalability challenges, the advantages
outweigh these drawbacks in many cases.
Group Members:

Roll No. Name Sign

21 Dethe Ujjwal Shriram

22 Dhonnar Rahul Dnyaneshwar

23 Game Pavan Shivaji

24 Gangurde Pranjali Shamrao

25 Garud Rutesh Balasaheb

Date: 08/04/2024
Class: T.E (Computer) Sem: II Sign of Subject Teacher

You might also like