INNER CODE UNIT · JavaScript
server
sebastiancarlos/beachpatrol · beachpatrol.js:163
const server = createServer((socket) => {
// Wire protocol helpers
const ERROR_SENTINEL = "BEACHPATROL_ERROR:";
const writeValue = (value) => {
// Write value to socket
let output = typeof value === "string" ? value : JSON.stringify(value);
if (!output.endsWith("\n")) output += "\n";
socket.write(output);
};
const writeError = (message) => {
// Log error to server console and to socket (with sentinel line)
console.log(`Error: ${message}`);
socket.write(`${ERROR_SENTINEL} ${message.replace(/\n/g, " ")}\n`);
socket.end();
};
socket.on("data", async (data) => {