├── backend ├── package.json └── server.js ├── frontend ├── script.js └── index.html ├── README.md └── LICENSE /backend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "chat-app", 3 | "version": "1.0.0", 4 | "main": "server.js", 5 | "dependencies": { 6 | "express": "^4.17.1", 7 | "cors": "^2.8.5", 8 | "socket.io": "^4.0.1" 9 | }, 10 | "scripts": { 11 | "start": "node server.js" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /frontend/script.js: -------------------------------------------------------------------------------- 1 | const socket = io('http://localhost:5000'); 2 | const messagesList = document.getElementById('messages'); 3 | 4 | socket.on('message', (data) => { 5 | const li = document.createElement('li'); 6 | li.textContent = data; 7 | messagesList.appendChild(li); 8 | }); 9 | 10 | function sendMessage() { 11 | const messageInput = document.getElementById('message'); 12 | socket.emit('message', messageInput.value); 13 | messageInput.value = ''; 14 | } 15 | -------------------------------------------------------------------------------- /frontend/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Чат-додаток 6 | 7 | 8 | 9 | 10 |

💬 Чат

11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Fullstack Chat App 2 | 3 | ## 📌 Опис 4 | Повноцінний чат-додаток з WebSockets, реєстрацією та повідомленнями 5 | 6 | ## 🚀 Використання 7 | 1. Перейдіть у папку `backend` та встановіть залежності: 8 | ```sh 9 | npm install 10 | ``` 11 | 2. Запустіть сервер: 12 | ```sh 13 | npm start 14 | ``` 15 | 3. Відкрийте `frontend/index.html` у браузері. 16 | 17 | ## 🔧 Додаткові можливості 18 | - Розширення функціоналу API. 19 | - Додавання авторизації користувачів. 20 | 21 | Ліцензія: MIT License 22 | -------------------------------------------------------------------------------- /backend/server.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const http = require('http'); 3 | const socketIo = require('socket.io'); 4 | const cors = require('cors'); 5 | 6 | const app = express(); 7 | const server = http.createServer(app); 8 | const io = socketIo(server, { cors: { origin: '*' } }); 9 | 10 | app.use(cors()); 11 | app.use(express.json()); 12 | 13 | io.on('connection', (socket) => { 14 | console.log('Користувач підключився'); 15 | socket.on('message', (data) => { 16 | io.emit('message', data); 17 | }); 18 | socket.on('disconnect', () => console.log('Користувач відключився')); 19 | }); 20 | 21 | server.listen(5000, () => console.log('Сервер чату запущено на порту 5000')); 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 adsstudio24 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | --------------------------------------------------------------------------------