John Abraham
John Abraham

Reputation: 18831

Type Error when static directory of to an expressJS app

I'm trying expose a bower_components directory on my express app and it keep throwing errors.

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');
});


How do I allow bower components to be visible when i hit my index.html?

enter image description here

Upvotes: 1

Views: 50

Answers (1)

Nicky McCurdy
Nicky McCurdy

Reputation: 19573

Express 3's API for this has changed. You need to call express.static(), not app.static().

var express = require('express');
var app = express();

app.use("/", express.static(__dirname + "/bower_components"));

Based on this answer.

Upvotes: 2

Related Questions