Implementation of a Real-Time Chat System Based on the MERN Stack and Socket.io with Natural Language Processing Integration for Automatic Sentiment Analysis

MERN Stack Socket.io Natural Language Processing Sentiment Analysis Lexicon-based

Authors

September 23, 2026

Downloads

Digital communication through chat platforms has become a primary medium for consultation services; however, the absence of non-verbal cues makes early detection of users’ emotional states challenging. This study implemented a real-time chat system based on the MERN Stack (MongoDB, Express.js, React.js, and Node.js) integrated with a lexicon-based Natural Language Processing (NLP) module to automatically detect message sentiment and risk levels. The system utilized Socket.io for bidirectional communication, with the NLP module positioned within the Controller layer and executed inline in the sendMessage event handler without requiring external services or message queues. Functional testing of the analyzeText() function across ten scenarios showed that all risk-level classifications matched the expected results. Sentiment classification achieved 80% accuracy, with two misclassifications attributed to the inherent limitations of lexicon-based matching in handling negation and substring ambiguity. All eleven Socket.io communication scenarios and seven REST API endpoints successfully passed testing. The MVC pattern within the MERN Stack demonstrated sufficient flexibility to accommodate an inline NLP module without requiring modifications to the Model or View layers. Furthermore, the tiered priority logic, which placed risky-word detection above sentiment scoring, maintained system reliability in critical cases despite occasional sentiment classification errors.