Download server.js from HugVPS/ws: direct link, hf CLI and curl.
- Browser
- Download file 570 Bytes
-
https://huggingface.co/spaces/HugVPS/ws/resolve/main/server.js
- Command line
-
hf download hf://spaces/HugVPS/ws/server.js
-
curl -L -o server.js https://huggingface.co/spaces/HugVPS/ws/resolve/main/server.js
570 Bytes
| // server.js | |
| const WebSocket = require('ws'); | |
| const child = require('child_process') | |
| const server = new WebSocket.Server({ port: 7860 }); | |
| server.on('connection', (ws) => { | |
| console.log('New client connected'); | |
| ws.on('message', (message, child) => { | |
| console.log(`Received: ${message}`); | |
| // Echo the message back to the client | |
| ws.send("Hi! This is hosted on HuggingFace Spaces.") | |
| }); | |
| ws.on('close', () => { | |
| console.log('Client disconnected'); | |
| }); | |
| }); | |
| console.log('WebSocket server is running on ws://localhost:7860'); |