1

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.

mak
  • 12,863
  • 5
  • 39
  • 47
julian
  • 4,434
  • 9
  • 41
  • 59
  • possible duplicate of [Render basic HTML view in Node JS Express?](http://stackoverflow.com/questions/4529586/render-basic-html-view-in-node-js-express) – zemirco Feb 20 '13 at 09:09

1 Answers1

1

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'));
});
novalagung
  • 9,699
  • 2
  • 50
  • 74