How to write a middleware class in Node.js

I have researched the topic for hours on Google and books and I could only find very specific implementations. I'm struggling to write a simple Middleware class in node JS with only plain vanilla javascript (no additional module like async, co,..). My goal is to understand how it works not to get the most optimised code.

I would like something as simple as having a string and adding new string to it thru the use of middleware.