DEV Community

Siddhesh Rajale
Siddhesh Rajale

Posted on

Summarizer Website using MEAN Stack

Introduction:

In today's fast-paced world, dealing with information overload is a common challenge. Picture having a tool that swiftly summarizes lengthy articles, allowing you to grasp the main points without spending excessive time reading. In this article, we'll walk you through the process of crafting a Summarizer Website using the MEAN Stack.

Project Preview:
Before we jump into the details, let's take a sneak peek at what our Summarizer Website will look like. This project is designed to offer users a straightforward and intuitive interface. Users can input large amounts of text and, in return, receive concise summaries.

**
Prerequisites:**
Before you start coding, make sure you have the following prerequisites installed on your system:

  • MongoDB

  • Express.js

  • Angular

  • Node.js

Approach:
Our approach to building the Summarizer Website using the MEAN Stack involves making the most of each component's strengths:

a. MongoDB: Setting up the Database

MongoDB acts as our database to store user data and summarized content. Begin by installing and configuring MongoDB on your system. Create a database for user information and another collection for storing summaries.

b. Express.js and Node.js: Building the Backend

Express.js, a web application framework for Node.js, serves as our backend framework. Node.js manages server-side operations. Develop RESTful APIs using Express to handle data flow between the frontend and the MongoDB database. Set up routes for user input, text processing, and summary retrieval.

**
c. Angular: Developing the Frontend**

Angular is our frontend framework, providing a robust and structured environment for UI development. Design a clean and user-friendly interface where users can input extensive text. Use Angular components to handle different parts of the UI, such as input forms and result displays. Implement services to communicate with backend APIs.

d. Connecting Frontend and Backend: Ensuring Seamless Communication

Establish a seamless connection between the frontend and backend. Use Angular services to make HTTP requests to the Express.js backend. Ensure proper handling of asynchronous operations and error cases. Implement mechanisms for sending user input from the frontend to the backend and receiving summarized content in return.

This approach ensures that each component in the MEAN Stack performs its specific role effectively. MongoDB stores data, Express.js and Node.js handle server-side operations, and Angular provides a dynamic and interactive user interface. As we proceed with the implementation steps, we'll delve deeper into each aspect, guiding you through the intricacies of building this comprehensive web application.

Let's break down the steps to create our Summarizer Website:

**
a. Set up the MongoDB Database:**

Think of the MongoDB database as a digital bookshelf where we neatly organize user data and summaries. To set it up, install MongoDB on your computer. It's like creating different shelves – one for storing user details and another for holding the summaries.

b. Create the Backend using Express.js and Node.js:

Now, let's talk about the brain behind our website – the backend. Express.js and Node.js are like a dynamic duo. Express.js is the traffic cop, guiding requests, and Node.js is the hardworking assistant, ensuring everything gets done efficiently. Together, they handle requests and communicate with the database.

c. Develop the Frontend using Angular:

Moving on to the part users interact with – the frontend. Angular helps us design a visually appealing and user-friendly interface. Think of it as crafting the front cover of a book – it's what users see and engage with. We'll create forms for users to input text and areas to display the summarized results.

d. Connect the Frontend and Backend:

Imagine the frontend and backend as two friends having a conversation. We want them to share information seamlessly. To achieve this, we'll set up a system where the user's input from the frontend travels to the backend. The backend processes it, and then the summarized result smoothly comes back to the frontend. It's like a friendly chat between the user interface and the brain behind the scenes.

Code Example
a. Set up the MongoDB Database

// Import required module
const mongoose = require('mongoose');

// Connect to MongoDB database
mongoose.connect('mongodb://localhost/summarizerDB', { useNewUrlParser: true, useUnifiedTopology: true });

// Define a schema for user data
const userSchema = new mongoose.Schema({
  username: String,
  email: String,
  // Add more fields as needed
});

// Define a schema for summaries
const summarySchema = new mongoose.Schema({
  userId: mongoose.Schema.Types.ObjectId,
  text: String,
  summary: String,
});

// Create models based on the schemas
const User = mongoose.model('User', userSchema);
const Summary = mongoose.model('Summary', summarySchema);

// Example usage:
// const newUser = new User({ username: 'JohnDoe', email: 'john@example.com' });
// newUser.save();

// const newSummary = new Summary({ userId: newUser._id, text: 'Lorem ipsum...', summary: 'Summary goes here.' });
// newSummary.save();
Enter fullscreen mode Exit fullscreen mode

b. Create the Backend using Express.js and Node.js

// Import required modules
const express = require('express');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');

// Create Express application
const app = express();
const port = 3000;

// Connect to MongoDB database
mongoose.connect('mongodb://localhost/summarizerDB', { useNewUrlParser: true, useUnifiedTopology: true });

// Middleware for parsing JSON
app.use(bodyParser.json());

// Define routes for handling user input and summaries
app.post('/api/submitText', async (req, res) => {
  try {
    // Process the incoming text and generate a summary
    const { userId, text } = req.body;
    const summary = processTextAndGenerateSummary(text);

    // Save the summary to the database
    const newSummary = new Summary({ userId, text, summary });
    await newSummary.save();

    res.status(200).json({ success: true, summary });
  } catch (error) {
    console.error(error);
    res.status(500).json({ success: false, error: 'Internal server error' });
  }
});

// Start the server
app.listen(port, () => {
  console.log(`Server is running on port ${port}`);
});

// Function to process text and generate a summary (replace with your actual summarization logic)
function processTextAndGenerateSummary(text) {
  // Simplified example: Just return the first 50 characters as a summary
  return text.slice(0, 50);
}
Enter fullscreen mode Exit fullscreen mode

c. Develop the Frontend using Angular

// Import required modules
import { Component } from '@angular/core';
import { HttpClient } from '@angular/common/http';

@Component({
  selector: 'app-summarizer',
  templateUrl: './summarizer.component.html',
  styleUrls: ['./summarizer.component.css'],
})
export class SummarizerComponent {
  userInput = '';
  summary = '';

  constructor(private http: HttpClient) {}

  submitText() {
    // Send user input to the backend for processing
    this.http
      .post<any>('http://localhost:3000/api/submitText', { userId: 'user123', text: this.userInput })
      .subscribe((response) => {
        if (response.success) {
          // Update the summary on the frontend
          this.summary = response.summary;
        } else {
          console.error(response.error);
        }
      });
  }
}
Enter fullscreen mode Exit fullscreen mode

Reference:
MongoDB Documentation:

MongoDB official documentation for installation and usage:

MongoDB Documentation

Express.js Documentation:

Express.js official documentation for creating the backend: Express.js Documentation

Angular Documentation:

Angular official documentation for building the frontend: Angular Documentation

Node.js Documentation:

Node.js official documentation for server-side JavaScript: Node.js Documentation

MEAN Stack Overview:

Understanding the MEAN Stack and its components: MEAN Stack Overview

HTTP Client for Angular - HttpClientModule:

Angular documentation for making HTTP requests: HttpClientModule - Angular Docs

Body-Parser Middleware for Express.js:

Body-parser middleware for handling JSON data in Express: Body-parser - npm

Mongoose Documentation:

Mongoose documentation for MongoDB object modeling: Mongoose Documentation

GitHub Repositories for Sample Projects:

Sample projects on GitHub for reference:

Angular Sample Project

Express.js Sample Project

Node.js Sample Project

Summarization Algorithms and NLP (Natural Language Processing):

Research and explore different summarization algorithms and NLP techniques for improving your text summarization logic.

By referring to these resources, you'll have a comprehensive understanding of the technologies used in your Summarizer Website project.

Top comments (0)