在expressJS应用程序的静态目录中键入Error

时间:2014-07-19 03:37:53

标签: javascript node.js express

我正在尝试在我的快递应用程序上公开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');
});


当我点击index.html时,如何让bower组件可见?

enter image description here

1 个答案:

答案 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