I have used .method to res, but the console showing me undefined.... Why?? help please??
const http = require('http');
http.createServer((req, res)=>{
console.log(res.method);
}).listen(9111);
I have used .method to res, but the console showing me undefined.... Why?? help please??
const http = require('http');
http.createServer((req, res)=>{
console.log(res.method);
}).listen(9111);
The console is showing you undefined
because there is no defined property method
on the response object. Unlike HTTP requests, HTTP responses do not have a method type.
Perhaps you were looking for req.method
?
res.method
(Response.Method) is not a property of Response
class.
https://nodejs.org/api/http.html#http_class_http_serverresponse
You're looking for req.method
(you are using res.method
...) :
const http = require('http');
http.createServer((req, res)=>{
console.log(req.method);
}).listen(9111);
Will print 'GET' when accessing localhost:9111/
...