Advertisement
fvasconcelos

Untitled

Feb 16th, 2022
1,240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const http = require("http");
  2.  
  3. http.createServer((req, res) => {
  4.     res.writeHead(200, { 'Content-Type': 'application/json' });
  5.  
  6.     if(req.url === "/produto"){
  7.         res.end(
  8.             JSON.stringify({
  9.                 message: "Rota de produto",
  10.             })
  11.         );
  12.     }
  13.  
  14.     if(req.url === "/usuarios"){
  15.         res.end(
  16.             JSON.stringify({
  17.                 message: "Rota de usuário",
  18.             })
  19.         );
  20.     }
  21.  
  22.     res.end(
  23.         JSON.stringify({
  24.             message: "Julius usando node.js",
  25.         })
  26.         );
  27.     }).listen(2345, () => console.log("Julius server is running! (Port 2345)"));
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement