-
Notifications
You must be signed in to change notification settings - Fork 55
feat: Added template for MERN JS Socket.io #175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a new MERN + Socket.io template to enable real-time chat functionality in JavaScript projects. The template includes both client and server code with Socket.io integration for bidirectional communication.
Key Changes
- Added new "MERN + Socket.io" template option with JavaScript-only support
- Implemented
mernSocketioSetupfunction to handle template installation - Updated CLI prompts to include the new stack option and restrict language choice to JavaScript for this template
Reviewed Changes
Copilot reviewed 34 out of 41 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
index.js |
Added "MERN + Socket.io" to stack choices and new conditional language prompts |
utils/project.js |
Added project setup flow for mern-socketio stack |
utils/installer.js |
Implemented mernSocketioSetup function for dependency installation |
utils/templateManager.js |
Formatting changes only (quote style normalization) |
templates/mern-socketio/** |
New template files for server and client with Socket.io integration |
Files not reviewed (4)
- templates/mern-socketio/client/package-lock.json: Language not supported
- templates/mern-socketio/javascript/client/package-lock.json: Language not supported
- templates/mern-socketio/javascript/server/package-lock.json: Language not supported
- templates/mern-socketio/server/package-lock.json: Language not supported
Comments suppressed due to low confidence (7)
templates/mern-socketio/javascript/server/controller/messages.js:1
- The Message model is imported but never used. The controller uses an in-memory array instead of the database model, making this import redundant and potentially confusing.
templates/mern-socketio/javascript/server/models/Message.js:1 - This file uses ES6 import syntax, but the package.json specifies 'type: commonjs', and other files in the server use CommonJS require() syntax. This will cause a runtime error.
templates/mern-socketio/javascript/server/index.js:1 - This comment indicates Mongoose is not needed, but the package.json still includes 'mongoose' as a dependency, and there's a Message model file. Either remove the dependency and model file, or update the comment to clarify the intended state.
templates/mern-socketio/client/src/components/Chat.js:1 - The socket URL is hardcoded differently here compared to socket.js which uses the same URL. This creates duplicated socket connections and inconsistent configuration. Consider importing the socket from socket.js instead.
templates/mern-socketio/client/src/index.js:1 - This file uses the deprecated ReactDOM.render API. React 18 requires using ReactDOM.createRoot() instead. The main.jsx file already has the correct implementation, so this file appears to be redundant.
templates/mern-socketio/client/src/components/Chat.js:1 - The Chat component listens for 'message' events, but the server emits 'newMessage' events (as seen in the controller). This event name mismatch will prevent messages from being received.
templates/mern-socketio/client/public/index.html:1 - This public/index.html file is redundant. Vite projects use index.html in the project root (which already exists), not in the public folder. This file will be ignored by Vite.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -0,0 +1,42 @@ | |||
| const Message = require('../models/Message'); | |||
Copilot
AI
Oct 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Message model is imported but never used. The controller uses an in-memory array instead of the database model, making this import redundant and potentially confusing.
| const Message = require('../models/Message'); |
| @@ -0,0 +1,20 @@ | |||
| import mongoose from 'mongoose'; | |||
Copilot
AI
Oct 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file uses ES6 import syntax, but the package.json does not specify 'type: module', and other files in the server use CommonJS require() syntax. This will cause a runtime error.
| require('dotenv').config(); | ||
| const express = require('express'); | ||
| const http = require('http'); | ||
| // Mongoose is no longer needed |
Copilot
AI
Oct 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment indicates Mongoose is not needed, but the package.json still includes 'mongoose' as a dependency, and there's a Message model file. Either remove the dependency and model file, or update the comment to clarify the intended state.
| // Mongoose is no longer needed | |
| // Mongoose is not used in this file. If not needed elsewhere in the project, remove the 'mongoose' dependency and any related model files. |
|
|
||
| const socket = io('http://localhost:5000'); // Adjust the URL as needed | ||
|
|
Copilot
AI
Oct 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The socket URL is hardcoded differently here compared to socket.js which uses the same URL. This creates duplicated socket connections and inconsistent configuration. Consider importing the socket from socket.js instead.
| const socket = io('http://localhost:5000'); // Adjust the URL as needed | |
| import socket from '../socket'; // Adjust the path as needed |
| import React from 'react'; | ||
| import ReactDOM from 'react-dom'; | ||
| import App from './App'; | ||
|
|
||
| ReactDOM.render( | ||
| <React.StrictMode> | ||
| <App /> | ||
| </React.StrictMode>, | ||
| document.getElementById('root') | ||
| ); No newline at end of file |
Copilot
AI
Oct 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file uses the deprecated ReactDOM.render API. React 18 requires using ReactDOM.createRoot() instead. The main.jsx file already has the correct implementation, so this file appears to be redundant.
| import React from 'react'; | |
| import ReactDOM from 'react-dom'; | |
| import App from './App'; | |
| ReactDOM.render( | |
| <React.StrictMode> | |
| <App /> | |
| </React.StrictMode>, | |
| document.getElementById('root') | |
| ); |
| socket.on('message', (message) => { | ||
| setMessages((prevMessages) => [...prevMessages, message]); | ||
| }); | ||
|
|
||
| return () => { | ||
| socket.off('message'); |
Copilot
AI
Oct 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Chat component listens for 'message' events, but the server emits 'newMessage' events (as seen in the controller). This event name mismatch will prevent messages from being received.
| socket.on('message', (message) => { | |
| setMessages((prevMessages) => [...prevMessages, message]); | |
| }); | |
| return () => { | |
| socket.off('message'); | |
| socket.on('newMessage', (message) => { | |
| setMessages((prevMessages) => [...prevMessages, message]); | |
| }); | |
| return () => { | |
| socket.off('newMessage'); |
index.js
Outdated
| { | ||
| name: "projectType", | ||
| type: "list", | ||
| message: "Select a project type:", | ||
| choices: [ | ||
| "MERN", | ||
| "MEAN", | ||
| "MEVN", | ||
| "MERN (Real-Time with Socket.io)", | ||
| "PERN", | ||
| ], | ||
| }, |
Copilot
AI
Oct 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This 'projectType' prompt appears to be unused - it's not referenced elsewhere in the code and doesn't affect the project setup flow. Additionally, it duplicates the stack selection functionality and includes 'PERN' which isn't implemented.
| { | |
| name: "projectType", | |
| type: "list", | |
| message: "Select a project type:", | |
| choices: [ | |
| "MERN", | |
| "MEAN", | |
| "MEVN", | |
| "MERN (Real-Time with Socket.io)", | |
| "PERN", | |
| ], | |
| }, |
| CLIENT_URL=http://localhost:3000 | ||
| MONGO_URI=URL No newline at end of file |
Copilot
AI
Oct 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The MONGO_URI is included in the .env.example, but the server code doesn't establish a database connection and uses in-memory storage. This configuration is misleading and should be removed or the documentation should clarify it's for future use.
| CLIENT_URL=http://localhost:3000 | |
| MONGO_URI=URL | |
| CLIENT_URL=http://localhost:3000 |
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <title>MERN Socket.io App</title> | ||
| </head> | ||
| <body> | ||
| <div id="root"></div> | ||
| </body> | ||
| </html> No newline at end of file |
Copilot
AI
Oct 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This public/index.html file is redundant. Vite projects use index.html in the project root (which already exists), not in the public folder. This file will be ignored by Vite.
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>MERN Socket.io App</title> | |
| </head> | |
| <body> | |
| <div id="root"></div> | |
| </body> | |
| </html> |
|
Hi @Farkhanda-Dalal , May i know why you have implemented this ?. |
3e3d91c to
291e82d
Compare

Description
Add a new MERN template that demonstrates real-time communication using Socket.io for Javascript.
Related Issue
Closes issue #168
Changes:
project.jsandinstaller.jsto copy the template files and install dependencies.Checklist
Proof of Work:
Created Folder using the template:
Frontend Test:
Testing Endpoints on Postman: