我正在尝试在我的快递应用程序上公开bower_components
目录并且它一直在抛出错误。
TypeError: Object #<ServerResponse> has no method 'static'
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
app.use("/", app.static(__dirname + "/bower_components"));
app.get('/', function(req, res){
res.sendfile('index.html');
});
io.on('connection', function(socket){
console.log('a user connected');
socket.on('disconnect', function(){
console.log('user disconnected');
});
});
http.listen(3000, function(){
console.log('listening on *: 3000');
});
答案 0 :(得分:2)
Express 3的API已经改变了。您需要致电express.static()
,而不是app.static()
。
var express = require('express');
var app = express();
app.use("/", express.static(__dirname + "/bower_components"));
基于this answer。