-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
24 lines (19 loc) · 749 Bytes
/
Copy pathserver.js
File metadata and controls
24 lines (19 loc) · 749 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import express from "express";
import path from "path";
const app = express();
const PORT = process.env.PORT || 3000;
// Serve static files from the public directory
app.use(express.static(path.join("/home/adesh/Desktop/random number generator", 'public')));
// Route for the homepage
app.get('/', (req, res) => {
res.sendFile(path.join("/home/adesh/Desktop/random number generator", 'public', 'index.html'));
});
// API endpoint to generate a random number
app.get('/api/random', (req, res) => {
const randomNumber = Math.floor(Math.random() * 100) + 1; // Change the range as needed
res.json({ number: randomNumber });
});
// Start the server
app.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});