gpt4 book ai didi

node.js - 使用 connect 时未定义不是一个函数

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

我正在尝试设置一个简单的 HTTP 服务器,并在 Node REPL 上进行连接。我尝试了以下方法,

var connect = require('connect');
var http = require('http');

var app = connect()
.use(connect.favicon())
.use(connect.logger())
.use(function(req,res) {
res.end('Hello World\n');
});

但是我收到以下错误,

TypeError: undefined is not a function
at repl:1:33
at REPLServer.defaultEval (repl.js:132:27)
at bound (domain.js:254:14)
at REPLServer.runBound [as eval] (domain.js:267:12)
at REPLServer.<anonymous> (repl.js:279:12)
at REPLServer.emit (events.js:107:17)
at REPLServer.Interface._onLine (readline.js:214:10)
at REPLServer.Interface._line (readline.js:553:8)
at REPLServer.Interface._ttyWrite (readline.js:830:14)
at ReadStream.onkeypress (readline.js:109:10)

我已经看过这个questionanswer但这似乎没有帮助。我已经确保 connect 已安装在我的 node_modules 目录中。

我做错了什么?

最佳答案

我知道为什么它不起作用。由于我使用的是 connect 版本 3.3.5,因此他们不再提供某些中间件。它们已被删除,您必须手动寻找它们。根据他们的 GitHub readme ,

Some middleware previously included with Connect are no longer supported by the Connect/Express team, are replaced by an alternative module, or should be superseded by a better module.

关于node.js - 使用 connect 时未定义不是一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29618729/

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