A backend server application that integrates sentiment analysis with secure file handling using Express.js and MongoDB.
- Machine Learning Model Integration: Integrates a pre-trained sentiment analysis machine learning model using VaderSentimentAnalysis with the server. 🤖
- Secure File Handling: Implements API endpoints for file uploads (audio, video, PDFs) and securely stores them in MongoDB. 🔒
- Authentication System: Develops a robust authentication system using Passport.js for user registration, login, and logout functionality. 🔐
The application follows the MVC (Model-View-Controller) pattern for a modular and maintainable structure.
- Models: Define the schemas for User and File. 📝
- Controllers: Handle the logic for authentication, sentiment analysis, and file handling. 💻
- Routes: Define the API endpoints for user authentication, sentiment analysis, and file upload/download. 🛣️
- Middlewares: Implement authentication middleware for secure access control. 🛡️
POST /api/auth/register
Request Payload:
{
"username": "example",
"email": "example@example.com",
"password": "password"
}
POST /api/auth/login
Request Payload:
{
"email": "example@example.com",
"password": "password"
}
Response Payload:
{
"token": "your_jwt_token"
}
POST /api/sentiment/analyze
Request Payload:
{
"text": "Your text for sentiment analysis"
}
Response Payload:
{
"sentiment": "positive",
"intensity": {
"neg": 0.0,
"neu": 0.654,
"pos": 0.346,
"compound": 0.75
}
}
POST /api/files/upload
Request Payload:
file: (binary)
Response Payload:
{
"message": "File uploaded successfully"
}
GET /api/files/:id
Response: File download
-
Clone the repository:
git clone https://github.com/your/repository.git
-
Install dependencies:
cd sentiment-analysis-server npm install
-
Set up environment variables:
Create a
.env
file in the root directory with the following variables:PORT=3000 MONGO_URI=your_mongodb_uri JWT_SECRET=your_jwt_secret
-
Start the server:
npm start
const vader = require('vader-sentiment');
exports.analyzeSentiment = (req, res) => {
// Implementation...
};
const multer = require('multer');
const File = require('../models/File');
const storage = multer.memoryStorage();
const upload = multer({
storage,
limits: { fileSize: 10 * 1024 * 1024 }, // 10 MB limit
fileFilter: (req, file, cb) => {
if (['audio/', 'video/', 'application/pdf'].some(type => file.mimetype.startsWith(type))) {
cb(null, true);
} else {
cb(new Error('Invalid file type'), false);
}
},
}).single('file');
exports.uploadFile = (req, res) => {
// Implementation...
};
const User = require('../models/User');
const jwt = require('jsonwebtoken');
const dotenv = require('dotenv');
dotenv.config();
exports.login = async (req, res) => {
// Implementation...
};
exports.register = async (req, res) => {
// Implementation...
};
Contributions are welcome! Feel free to open an issue or submit a pull request.
NAME: RAJENDRA BISOI
MAIL: rajendrabisoi23@gmail.com. 📝