这是我在节点 js 中的代码:
var http = require('http');
var options = {
host : '127.0.0.1',
port: 8124,
path: '/',
method: 'GET'
};
http.request(options, function(res){
console.log("Hello!");
}).end();
process.on('uncaughtException', function(err){
console.log(err);
});
当我编译它时,编译器向我显示以下错误:
编辑:有快递的作品,但如果我想让它在没有快递的情况下工作,我该怎么办?
为了解决这个问题,在之前的代码中添加服务器代码就足够了。
var http = require('http');
var options = {
host : '127.0.0.1',
port: 8124,
path: '/',
method: 'GET'
};
http.request(options, function(res){
console.log("Hello!");
}).end();
process.on('uncaughtException', function(err){
console.log(err);
});
http.createServer((req, res)=>{
res.writeHead(200, {'Content-type': 'text/plain'})
res.end()
}).listen(8124)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句