-1

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);
  • What do you mean by "I have used .method to res", can you explain more, and provide additional code explaining what is method? – Basel Issmail Mar 06 '19 at 17:41

3 Answers3

0

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?

Raphael Serota
  • 2,157
  • 10
  • 17
0

res.method (Response.Method) is not a property of Response class.

https://nodejs.org/api/http.html#http_class_http_serverresponse

mralanlee
  • 479
  • 5
  • 15
0

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/...

MarcoS
  • 17,323
  • 24
  • 96
  • 174