I try to make a GET request to some site (not mine own site) via http module of node.js version 0.8.14. Here is my code (CoffeeScript):
options =
ho
When using http.request(), you have to at some point call request.end().
req = http.request options, (res) ->
# ...
req.on 'error', # ...
req.end() # <---
Until then, the request
is left open to allow for writing a body. And, the error is because the server will eventually consider the connection to have timed out and will close it.
Alternatively, you can also use http.get() with GET
requests, which will call .end()
automatically since GET
requests aren't normally expected to have a body.