Created
April 28, 2020 15:38
-
-
Save emerson-pereira/63528c7b6162550d6f1c22be01f50752 to your computer and use it in GitHub Desktop.
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 = 8080; | |
const server = http.createServer((req, res) => { | |
if (req.url === "/") { | |
res.end("Welcome home!"); | |
} | |
if (req.url === "/user") { | |
if (req.method === "GET") { | |
res.end("This is the user page"); | |
} | |
if (req.method === "POST") { | |
res.writeHead(201); | |
res.end("User added sucessfully"); | |
} | |
} | |
}); | |
server.listen(PORT, () => { | |
console.log(`Server listening on port ${PORT}`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment