Skip to content

Instantly share code, notes, and snippets.

@lebowvsky
Last active March 26, 2020 12:56
Show Gist options
  • Save lebowvsky/e090a73ffaa8b34db548315f80aa0f99 to your computer and use it in GitHub Desktop.
Save lebowvsky/e090a73ffaa8b34db548315f80aa0f99 to your computer and use it in GitHub Desktop.
NodeJS creer un serveur http
const http = require('http');
const url = require('url');
const port = 8000;
const requestHandler = (request, response) => {
const urlObj = url.parse(request.url, true).query
if(urlObj.name && urlObj.city){
response.end(`Hello ${urlObj.name} How are you in your beautiful city of ${urlObj.city}!!!!`);
} else {
response.end("Please provide name AND city parameters");
}
}
const server = http.createServer(requestHandler);
server.listen(port, (err) => {
if(err){
console.error('It does not work');
} else {
console.log(`The server is listening the port : ${port}`)
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment