Created
November 1, 2021 21:23
-
-
Save vmalep/8d768fbc88c9042537986129a4f32682 to your computer and use it in GitHub Desktop.
Quest 383 / Pierre van Male
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require('http') | |
const url = require('url') | |
const port = 8000 | |
const requestHandler = (request, response) => { | |
console.log(request.url) | |
const current_url = new URL(request.url, 'http://localhost:8000') | |
const search_params = current_url.searchParams | |
const name = search_params.get('name') | |
const city = search_params.get('city') | |
name && city ? response.end(`Hello, ${name} from ${city}!`) : response.end('Please provide name AND city parameters') | |
}; | |
const server = http.createServer(requestHandler) | |
server.listen(port, (err) => { | |
if (err) { | |
console.error('Something bad happened') | |
} else { | |
console.log(`server is listening on ${port}`) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment