Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
const http = require('http');
const port = 8000;
const url = require('url');
const requestHandler = (request, response) => {
const parsedUrl = url.parse(request.url, true);
if(parsedUrl.query.name && parsedUrl.query.city){
response.end(`Hello, ${parsedUrl.query.name} from ${parsedUrl.query.city}`);
}else{
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