Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
const express = require('express')
const app = express()
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) {
app.get('/', async function(req, res) {

// Start our reponse string
var response = 'Hello ';
// Start our response string
let response = 'Hello ';

// Lets fetch our username for somewhere
getUserName(function(err, name) {
await getUserName(function(err, name) {
if (err) {
return res.status(500).send('Something is not right!')
}
// Join our strings
response = response + name;
response += name;
res.send(response);
});

// Return response to client
res.send(response)

})


// This function will return our username to print
function getUserName(callback) {
async function getUserName(callback) {
// Wrapping it in a timeout
// to simulate if this is a database request
setTimeout(function() {
Expand All @@ -34,4 +35,4 @@ function getUserName(callback) {
}

// Port for server to start and listen on
app.listen(3000, () => console.log('Buggy app listening on port 3000!'))
app.listen(3000, () => console.log('Buggy app listening on port 3000!'));