Created
November 15, 2021 10:30
-
-
Save sele-nap/2ad394f3377e110fb67564342e000eb9 to your computer and use it in GitHub Desktop.
WCS quest // Paramétrer une application avec dotenv
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) => { | |
const parsedUrl = url.parse(request.url, true) | |
console.log(request.url); | |
if (request.url === '/') { | |
response.end('Hello Node.js Server!'); | |
} else { | |
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