550725 (2) [Avatar] Offline
#1
The express.static() - feature calls next if the static file requested in not present. BUT it doesn't set off the error handling mode - but it seems as if it should. is there any way to do this because based on the exercises in (chapter 4) i did the follow when express.static DID NOT find the file requested - but it seems a redudant step since we already know that the file is not there:

```
const staticPath = path.join(__dirname, "static"smilie;
app.use(express.static(staticPath));

// if file was not found in previous express.static call :

app.use((req, res, next) => {
res.sendFile(path.join(__dirname, "static", req.url), function(err) {
if(err) {
next(new Error("Error sending the file that was requested"smilie);
}
})
})

app.use((err, req, res, next) => {
console.error(err);
next(err);
});

...

```
Evan Hahn (70) [Avatar] Offline
#2
You're right that it is a redundant step. You shouldn't need to use sendFile in the express.static example.

(That's not to say you'll never use sendFile and express.static in the same codebase, but it isn't needed in Chapter 4's examples.)