import {appendFile, readFile} from 'node:fs/promises'; import {createServer} from 'node:http'; createServer(async (request, response) => { const chat = new URL(`http://a${request.url}`).searchParams.get('chat'); if (chat) { await appendFile('a.txt', `${chat}\n`, {flag: 'a+', encoding: 'utf8'}); response.writeHead(303, {location: '/'}).end(); // without query } else { response.writeHead(200, { 'content-type': 'text/html', }).end( `
${
				(await readFile('a.txt', {flag: 'a+', encoding: 'utf8'}))
					// ugh, fine, i'll html escape it. no xss for you
					.replace(/[<>&'"]/g, match => ({
						'<': '<',
						'>': '>',
						'&': '&',
						'\'': ''',
						'"': '"',
					})[match])
			}