A full-stack real-time chat application built with Next.js, Socket.IO, and Prisma.
This project combines Next.js for the frontend and API backend with Socket.IO for real-time communication. It supports features like live chat, active user tracking, and persistent message storage using PostgreSQL.
Key technologies used:
- Next.js: For building the frontend and API routes.
- Socket.IO: For real-time communication.
- Prisma: For database management with PostgreSQL.
- TypeScript: For type-safe development.
- Tailwind CSS: For styling the frontend.
- Real-Time Chat: Send and receive messages instantly.
- Active User Tracking: See who is online in real-time.
- Persistent Messages: Messages are stored in a PostgreSQL database.
- Authentication: Secure user authentication using Clerk or JWT.
- Responsive UI: A modern and responsive design using Tailwind CSS.
- Node.js: v20.x or higher.
- PostgreSQL: A running PostgreSQL instance.
- Redis (optional): For scaling Socket.IO.
-
Clone the repository:
git clone https://github.com/vitorcoolV2/socket-next-template.git cd socket-next-template -
Install dependencies:
npm install
-
Set up environment variables:
cp .env.example .env
Update the
.envfile with your database credentials and other required settings. -
Run database migrations (if using Prisma):
npx prisma migrate dev
-
Start the services:
- Socket.IO Server:
npm run io
- Next.js Application:
npm run dev
- Socket.IO Server:
- Access the Next.js application at
http://localhost:3000. - The Socket.IO server runs at
http://localhost:3001.
Both services support debugging using the Node.js Inspector API:
- Socket.IO Server: Debugger listens on
ws://127.0.0.1:9229. - Next.js App: Debugger listens on
ws://127.0.0.1:9230.
For more details, see the Node.js Inspector Documentation.
Here are the available scripts in this project:
| Script | Purpose |
|---|---|
npm run io |
Start the Socket.IO server. |
npm run dev |
Start the Next.js development server. |
npm run build |
Build the Next.js application. |
npm run start |
Start the Next.js production server. |
npm run lint |
Check for linting errors. |
npm run test |
Run Jest tests. |
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bug fix:
git checkout -b feature-name
- Commit your changes:
git commit -m "Add feature or fix" - Push your branch:
git push origin feature-name
- Submit a pull request.
For more details, see our Contributing Guidelines.
This project is licensed under the MIT License.