I decided to use couthdb as my default database, so I used HTTP. request, but the request could not be sent out.
Locate row 1144
// Require ("HTTP "). request (options, CB) function clientrequest (options, CB) {var self = This; outgoingmessage. call (Self); self. agent = options. agent === undefined? Globalagent: options. agent; // whether to use the agent var defaultport = options. defaultport | 80; var Port = options. port | defaultport; var host = options. hostname | options. host | 'localhost'; If (options. sethost = undefined) {var sethost = true;} self. socketpath = options. socketpath; VaR method = self. method = (options. method | 'get '). touppercase (); self. path = options. path | '/'; If (CB) {self. once ( 'Response', CB);} If (! Array. isarray (options. headers) {If (options. headers) {var keys = object. keys (options. headers); For (VAR I = 0, L = keys. length; I
No result. This is just a class. Continue.
Exports. request = function (options, CB) {If (typeof Options = 'string') {Options = URL. parse (options);} If (options. protocol & options. protocol! = 'HTTP: ') {Throw new error ('Protocol:' + options. protocol + 'not ororted. ');} return New clientrequest (options, CB) ;}; exports. get = function (options, CB) {var Req = exports. request (options, CB); req. end (); Return req ;};
It is found that the only thing HTTP. Get needs to do more than http. request is to add a req. End () and crash!
In addition, this callback really only has one parameter, that is, the second parameter of HTTP. createserver (function (req, Res) {}) is the same!
We only need to add an end to makeProgramRunning! (First install and start couthdb)
var HTTP = require ('http'); var Options = {port: 5984, method: 'get'}; // The callback has only one parameter, namely, HTTP. createserver (function (req, Res) {}) var Req = http. request (options, function (RES) {console. log ('status: '+ Res. statuscode); console. log ('headers: '+ JSON. stringify (res. headers); Res. setencoding ('utf8'); var body = "" res. on ('data', function (chunk) {body + = chunk}); Res. once ("end", function () {var JSON = JSON. parse (body); console. log (JSON)}; req. end () req. on ('error', function (e) {console. log ('problem with request: '+ E. message) ;});