express3 - trying to route files

Problem

I am trying to route files in express3 but I get a problem.
So here is the code for routing the files -

var app = require('express')(),
server = require('http').createServer(app),
io = require('socket.io').listen(server);

server.listen(8080);

// routing
app.get('/', function (req, res) {
    res.sendfile("index/index.html");
    app.use(app.static(__dirname + 'index'));
});

When I open localhost:8080 in Chrome it gives me an error :

TypeError: Object function app(req, res){ app.handle(req, res); } has no method 'static'

What I did wrong?

All of my HTML/CSS/JS files are in the index directory.

Problem courtesy of: Israelg99

Solution

static is static function from express, you cannot access it from instance object crated by express. you need to assign required express to different variable.

var express = require('express'),
    app = = express(),
    server = require('http').createServer(app),
    io = require('socket.io').listen(server);

server.listen(8080);

// routing
app.get('/', function (req, res) {
    res.sendfile("index/index.html");
    app.use(express.static(__dirname + 'index'));
});
Solution courtesy of: Noval Agung Prayogo

Discussion

There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.