-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
28 lines (24 loc) · 952 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const express = require('express')
const app = express()
const port = 3000
app.get('/', (req, res) => {
res.send('Hello World!')
})
// // Example route for getting data from an API
// app.get('/api/data/:id', (req, res) => {
// // Check if the id is valid
// if (!isValidId(req.params.id)) return res.status(400).send({ error: 'Invalid ID ' })
// // Delay response by 1 second to simulate server latency
// setTimeout(() => {
// res.send(`Data for ${req.params.id}`)
// }, 1000)
// })
// function isValidId(id) {
// // A very simple validation check - in a real-world scenario you would want much more robust checks
// return !isNaN(parseInt(id)) && parseInt(id) > 0
// }
// // Start Express on the specified port - default is 3000 but can be changed here
// app.listen(port, () => console.log(`Server running at http://localhost:${port}/`))
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})