julian
julian

Reputation: 4714

express3 - trying to route files

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.

Upvotes: 1

Views: 76

Answers (1)

novalagung
novalagung

Reputation: 11502

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

Upvotes: 1

Related Questions