I start with Node.js, so, according to the requirements of the project, I try to call the REST service from Node.js, I got information on how to call peace from this SO question . Here is the code to call the rest:
var options = { host: url, port: 80, path: '/resource?id=foo&bar=baz', method: 'POST' }; http.request(options, function(res) { console.log('STATUS: ' + res.statusCode); console.log('HEADERS: ' + JSON.stringify(res.headers)); res.setEncoding('utf8'); res.on('data', function (chunk) { console.log('BODY: ' + chunk);
The problem is that I want to send chunk as a response to the browser, I tried res.write() , but it throws me an error "write method not found". I looked in the docs everywhere, but all they give is console.log. Can someone tell me how can I send this data in response to the browser?
source share