我使用运行以下命令的 NPM 安装了连接模块:
npm install connect
它在 /Download/usr/node_modules/connect 文件夹中创建了模块。我创建了一个使用连接模块的文件
var connect = require('connect');
var util = require('util');
function sendjson(res,obj)
{
res.writeHead(200,{'Content-Type':'application/json',});
var objstr = JSON.stringify(obj);
util.debug('SENDJSON' + objstr);
res.end(objstr);
}
var server = connect.createServer(
connect.router(function(app){
app.get('/foo', function(req,res){
sendjson(res,{path:'foo'});
})
app.get('/bar', function(req,res){
sendjson(res,{path:'bar'});
})
})
);
server.listen(3000);
我运行 node createServer.js 并在终端中抛出,它给了我以下错误。
找不到模块“连接”