How do I use app.get(" * ") with modules?

Right now, I have a project like this:

|--.
|--./file1
|--./file2
|--./file3
|--./controller
|--./import
|--./package.json

File1, file2, etc have an Express route in them, and I import them in ./controller with require statements. I want controller to be a very clean file - it just has imports and function calls, nothing else - no Express routes.

Now, I want to set up a 404 page with app.get("*",.... I tried putting it at the end of ./file3, but it didn’t work - do i have to create a new file just for 404 requests for it to work?

It is the same way the other endpoints are.

1 Like

I’m not sure you can do it with hidden files but this worked for me in the root of the project

app.get('/filename/' + '*', function(request, response) {
  response.sendFile(__dirname + '/views/404.html'); 
});

Haha sorry, the dots just represent the file structure, not the actual file names.

1 Like