Node.Js error - listener must be a function -
i trying build endpoint /order.... order post request can made.
var http = require('http'); var options = { hostname: '127.0.0.1' ,port: '8080' ,path: '/order' ,method: 'get' ,headers: { 'content-type': 'application/json' } }; var s = http.createserver(options, function(req,res) { res.on('data', function(){ // success message receiving request. // console.log("we have received request successfully."); }); }).listen(8080, '127.0.0.1'); // understand options object has defined this. req.on('error', function(e){ console.log("there problem request:\n" + e.message); }); req.end();
i error "listener must function"....when trying run command line - "node sample.js"
i want able run service , curl it. can proof read code , give me basic directions on going wrong? , how may improve code.
http.createserver()
not take options
object parameter. parameter listener, must function, not object.
here's simple example of how works:
var http = require('http'); // create http server var srv = http.createserver(function (req, res) { res.writehead(200, {'content-type': 'text/plain'}); res.end('okay'); }); srv.listen(8080, '127.0.0.1');
Comments
Post a Comment