-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhello_express_server.js
More file actions
38 lines (27 loc) · 1018 Bytes
/
hello_express_server.js
File metadata and controls
38 lines (27 loc) · 1018 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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const express = require('express')
const app = express()
const port = 3000
app.get('/', (req, res) => {
res.send('Hello Express!')
})
app.use(express.static('public'))
app.listen(port, () => {
console.log(`Example app listening on port http://localhost:${port}`)
console.log(`You may connect to http://localhost:3000/cake.jpeg to see a cake.`)
})
app.get('/users/:userId/books/:bookId', (req, res) => {
let userId = req.params.userId
let bookId = req.params.bookId
console.log(`Querying ${userId} - book ${bookId}`)
let result = {"book":`${bookId}`,"content":`a book of ${userId}`}
res.json(result)
})
app.get('/users/:userId', (req, res) => {
res.send(`you are now querying ${req.params.userId}`)
})
const birds = require('./bird_module/router')
app.use('/birds', birds)
let cal = require('./calculation/fast-multiply')
console.log(`number 629 triple is ${cal.triple(629)}`)
let { do_double } = require('./calculation/fast-multiply')
console.log(`number 629 double is ${do_double(629)}`)