gpt4 book ai didi

node.js - node+now.js+connect 给我一个错误

转载 作者:太空宇宙 更新时间:2023-11-03 23:11:03 27 4
gpt4 key购买 nike

我安装了node_module connect以使用静态方法。这是我的代码:

var http = require('http');
var connect = require('connect');
var nowjs = require("now");
var app = connect();

app.use(connect.static('/var/www/www.domain.com/htdocs'));

app.use(function(req, res){
res.end();
});

http.createServer(app).listen(8001);


var everyone = nowjs.initialize(http);

但是我收到一个错误:

[TypeError: Object #<Object> has no method 'listeners'] TypeError: Object #<Object> has no method 'listeners'
at Object.wrapServer (/home/chris/nowjs/node_modules/now/lib/fileServer.js:23:29)
at [object Object].initialize (/home/chris/nowjs/node_modules/now/lib/now.js:181:14)
at Object.<anonymous> (/home/chris/nowjs/multiroomchat_server.js:15:22)
at Module._compile (module.js:446:26)
at Object..js (module.js:464:10)
at Module.load (module.js:353:31)
at Function._load (module.js:311:12)
at Array.0 (module.js:484:10)
at EventEmitter._tickCallback (node.js:190:38)

怎么了?

最佳答案

http 变量是对 http 模块的引用,而不是对创建的 http 服务的引用。您需要获取从 createServer() 传回的变量并将其传递给 Now.js。值得庆幸的是 listen() 将其链接起来,您不必断开该线路。

var server = http.createServer(app).listen(8001);
var everyone = nowjs.initialize(server);

关于node.js - node+now.js+connect 给我一个错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10889256/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com