You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
631 B
JavaScript
21 lines
631 B
JavaScript
// Node.js Routing with HTTP Method
|
|
const http = require('http');
|
|
const port = 4000
|
|
const app =http.createServer((request,response) =>{
|
|
if(request.url == '/items' && request.method == 'GET'){
|
|
|
|
response.writeHead(200,{'Content-Type':'text/plain'});
|
|
response.end('Data retrieve from the datebase');
|
|
}
|
|
|
|
if(request.url == '/items' && request.method == 'POST'){
|
|
|
|
response.writeHead(200,{'Content-Type':'text/plain'});
|
|
response.end('Data to be sent to the datebase');
|
|
}
|
|
});
|
|
// or const http =require.createServer(function(request,response){
|
|
// });
|
|
app.listen (port,() => console.log(`Server running at localhost:${port}`));
|
|
|