| const http = require('http'); |
|
|
| |
| function generatePin() { |
| return Math.floor(1000 + Math.random() * 9000).toString(); |
| } |
|
|
| const server = http.createServer((req, res) => { |
| if (req.url === '/') { |
| const pin = generatePin(); |
| const html = ` |
| <!DOCTYPE html> |
| <html lang="en"> |
| <head> |
| <meta charset="UTF-8" /> |
| <meta name="viewport" content="width=device-width, initial-scale=1" /> |
| <title>4-Digit PIN Generator</title> |
| <style> |
| body { |
| font-family: Arial, sans-serif; |
| margin: 2rem; |
| text-align: center; |
| } |
| .pin { |
| font-size: 4rem; |
| font-weight: bold; |
| color: #2c3e50; |
| margin-top: 2rem; |
| } |
| button { |
| margin-top: 2rem; |
| padding: 0.5rem 1rem; |
| font-size: 1.2rem; |
| cursor: pointer; |
| } |
| </style> |
| </head> |
| <body> |
| <h1>Random 4-Digit PIN Generator</h1> |
| <div class="pin">${pin}</div> |
| <button onclick="location.reload()">Generate New PIN</button> |
| </body> |
| </html> |
| `; |
| res.writeHead(200, {'Content-Type': 'text/html'}); |
| res.end(html); |
| } else { |
| res.writeHead(404, {'Content-Type': 'text/plain'}); |
| res.end('404 Not Found'); |
| } |
| }); |
|
|
| const PORT = process.env.PORT || 3000; |
| server.listen(PORT, () => { |
| console.log(`Server running at http://localhost:${PORT}/`); |
| }); |