forked from alanmoran/express-app-bug
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
37 lines (29 loc) · 868 Bytes
/
main.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
29
30
31
32
33
34
35
36
37
const express = require('express')
const app = express()
// This is out apps base route. Any request to localhost:3000/
// is handled here
app.get('/', function(req, res) {
// Start our reponse string
var response = 'Hello ';
// Lets fetch our username for somewhere
getUserName(function(err, name) {
if (err) {
return res.status(500).send('Something is not right!')
}
// Join our strings
response = response + name;
// Return response to client
res.send(response)
});
})
// This function will return our username to print
function getUserName(callback) {
// Wrapping it in a timeout
// to simulate if this is a database request
setTimeout(function() {
// Return the username
return callback(null, "Joe Bloggs")
}, 200)
}
// Port for server to start and listen on
app.listen(3000, () => console.log('App listening on port 3000!'))