here is my code
var express=require("express"); var app=express(); var port=8181; app.use(express.static(__dirname)); app.listen(port);
it is serving static file properly
I want to log when a file with an extension .xls is being requested
how can i achieve it ?
The path
core module gives you the tools to deal with this. So, just put this logic in a middleware before your static middleware, like:
var express = require("express"); var path = require("path"); var app = express(); var port = 8181; app.use(function (req, res, next) { var filename = path.basename(req.url); var extension = path.extname(filename); if (extension === '.css') console.log("The file " + filename + " was requested."); next(); }); app.use(express.static(__dirname)); app.listen(port);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With