Skip to content Skip to sidebar Skip to footer

Expressjs Static Files Not Being Served

I'm stuck on a frustrating problem. My static files aren't being served by express js, and instead my global catch all get handler is being hit. My directory structure: node/apps/w

Solution 1:

If app.use(app.router) is above the app.use(express.static(...)) line then the routes will trump the static. Your app.get('*',...) line is part of the routes.

See Node.js / Express.js - How does app.router work? for more info.

Solution 2:

var express = require("D:/node/express/modules/express");
 var path=require("D:/node/express/modules/path");
 var app = newexpress();
 app.get('/',function(req,res){
     res.sendFile(path.join(__dirname,'/index.html'));
 });
 app.get('/about',function(req,res){
    res.sendFile(path.join(__dirname,'/about.html'));
 });
 app.listen(1000);

here var express and var path are modules path here you can use this simple code to serve static files.

Post a Comment for "Expressjs Static Files Not Being Served"