Skip to content

Instantly share code, notes, and snippets.

@emerson-pereira
Created April 28, 2020 15:38
Show Gist options
  • Save emerson-pereira/63528c7b6162550d6f1c22be01f50752 to your computer and use it in GitHub Desktop.
Save emerson-pereira/63528c7b6162550d6f1c22be01f50752 to your computer and use it in GitHub Desktop.
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