Created
March 18, 2019 17:40
-
-
Save bapHyv/e2d5b0f4081285dc119bb5b3b95b3b11 to your computer and use it in GitHub Desktop.
NodeJS - Créer un serveur HTTP
This file contains hidden or 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 port = 3000; | |
| const requestHandler = (request, response) => { | |
| let arrUrl = request.url.split("/"); | |
| console.log(arrUrl); | |
| console.log("je suis request.url " + request.url); | |
| if (request.url === "/") { | |
| response.end("Bienvenue sur votre serveur !!"); | |
| } else if (request.url === "/contact") { | |
| response.end("Nous ne sommes pas joignables pour le moment ! "); | |
| } else if (arrUrl[1] === "display") { | |
| response.end(`Vous tentez d'afficer le profil de ${arrUrl[2]}`); | |
| } | |
| }; | |
| const server = http.createServer(requestHandler); | |
| server.listen(port, err => { | |
| if (err) { | |
| throw new Error("Something bad happened..."); | |
| } | |
| 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