当我调用此node.js文件
时var connect = require('connect');
var app = connect();
app.use(connect.static('public'));
app.listen(3000);
我马上得到
app.use(connect.static('public'));
^
TypeError: Object function createServer() {
function app(req, res, next){ app.handle(req, res, next); }
merge(app, proto);
merge(app, EventEmitter.prototype);
app.route = '/';
app.stack = [];
return app;
} has no method 'static'
使用Connect 3.0.1,集成模块是否有变化? 如果是,那么它是如何工作的呢?
答案 0 :(得分:13)
npm install serve-static
上面的代码现在应该是这样的:
var connect = require('connect');
var serveStatic = require('serve-static');
var app = connect();
app.use(serveStatic('public'));
app.listen(3000);
答案 1 :(得分:1)
我必须安装connect和serve-static
npm install connect
然后输入:
npm install serve-static
下面的代码会给您一条很好的消息,告诉您服务器已连接到端口3000。
var connect = require('connect');
var serveStatic = require('serve-static');
var app = connect();
var port = 3000;
app.use(serveStatic(__dirname));
app.listen(port);
console.log('You are connected at port '+port);