A playful Node.js Express server packed with fun endpoints, fake data generation, system info, a guessing game, file upload, ASCII art, a rock-paper-scissors API, and real-time features using Socket.IO!
- Random Jokes:
/joke– Get a random joke in JSON. - System Info:
/sysinfo– Fetch server system details. - Fake Person:
/fake-person– Generate fake user data. - Guessing Game:
/game– Play a web-based "Guess the Number" game. - File Upload:
/upload– Upload files withmultipart/form-data. - ASCII Art:
/ascii-art– Enjoy random ASCII art. - Rock-Paper-Scissors:
/rps/:choice– Play rock-paper-scissors via API. - Socket.IO:
- Real-time system info broadcast.
- Simple chat example.
- Node.js >=14.x
-
Clone this repo or copy the code.
-
Install dependencies:
npm install express os chance multer socket.io
-
(Optional) Create a
public/directory for static files.
node index.jsThe server will start on port 3000 and display both local and network URLs.
- GET /
Main HTML page with route links.
- GET /joke
Returns a random joke:{ "joke": "..." }
- GET /sysinfo
Returns JSON with host, platform, architecture, CPU count, RAM, and uptime.
- GET /fake-person
Generates random name, email, profession, credit card, and IP.
-
GET /game
Interactive HTML form to guess a number between 1-100. -
GET /guess?guess=NUMBER
Submits your guess, returns HTML with result.
- POST /upload (form-data, field:
file)
Uploads a file, returns upload info in JSON.
- GET /ascii-art
Returns a random piece of ASCII art as HTML.
- GET /rps/:choice
Play rock-paper-scissors!
Example:/rps/rock
Returns JSON:{ "userChoice": "rock", "computerChoice": "scissors", "result": "You win!" }
- All files in the
public/directory are served at the root.
- Connect via Socket.IO at
/ - On connect:
- Receives system info (
cpu,mem) every 5 seconds. - Emits/receives chat messages with the
chatevent.
- Receives system info (
const socket = io('http://localhost:3000');
socket.on('sysinfo', data => console.log(data));
socket.emit('chat', 'Hello!');
socket.on('chat', msg => console.log(msg));- All logic is in a single file (e.g.,
index.js). - Static files can be placed in
public/. - Uploaded files go to
uploads/.
- Add more jokes, ASCII art, or custom endpoints as you wish!
- Use the
/publicdirectory for your client-side HTML/CSS/JS.
This project uses:
By Nang'at