express.js - use middleware for non static urls only

How do i create middleware that runs on all urls that arent serving static files?

i was thinking of checking if req.url doesnt start with "/js/", "/css/" or "/images/" but there must be a better way

The easiest (and fastest) way is to put your static file middleware ahead of your 'catch all' middleware:

app.use(express.static(STATIC_DIR_HERE));
app.use(function notStatic(req, res, next) {
  // everything here will be non-static routes
});

(where app is your express instance)