Create public/index.html
Browse files12345678910111213141516171819202122232425262728293031323334353637383940414243<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Socket.IO Chat</title> <style> ul { list-style-type: none; padding: 0; } li { padding: 8px; margin-bottom: 10px; background: #f1f1f1; } </style></head><body> <h1>Socket.IO Chat</h1> <ul id="messages"></ul> <form id="form" action=""> <input id="input" autocomplete="off" /><button>Send</button> </form>
<script src="/socket.io/socket.io.js"></script> <script> const socket = io();
const form = document.getElementById('form'); const input = document.getElementById('input'); const messages = document.getElementById('messages');
form.addEventListener('submit', function(e) { e.preventDefault(); if (input.value) { socket.emit('chat message', input.value); input.value = ''; } });
socket.on('chat message', function(msg) { const item = document.createElement('li'); item.textContent = msg; messages.appendChild(item); window.scrollTo(0, document.body.scrollHeight); }); </script></body></html>public/index.htmlAdded+43