Reputation: 473
Im attempting to serve files with the assistance of express.static and am having difficulty getting it to work.
My code includes the following:
var app = express();
app.use(express.static(__dirname + '/public'));
var app_router = express.Router();
app_router.get('/', function(req, res){
res.sendfile('/test.html');
});
app.use('/', app_router);
This does not function in serving test.html, however if I replace it with ./public/test.html it is served correctly(Basically bypassing express.static)
Any assistance would be appreciated. Ive looked around and found code similar to mine that appears to be working however I must be missing something relatively simple and would appreciate another set of eyes. Thanks!
Upvotes: 0
Views: 36
Reputation: 888087
You're misunderstanding express.static()
.
res.sendFile()
takes a path to a file on disk, and has nothing to do with express.static()
.
express.static()
handles requests to paths matching files in the folder you pass it.
Upvotes: 1