I've created a simple node framework just to get the idea behind node frameworks like express.
check the code in this repo.
Simple Node framework
- A simple node framework with zero dependency
- An Express like framework that implements the middleware pattern
- For demonstration purpose only, not for production (maybe later)
To get the idea behind node frameworks specially express (the most popular node framework)
- Middlewares handling is being implemented using the chain of responsibility pattern, check
lib/App.jsto see the implementaion details
- Extending the
http.ServerResponseobject functionality by adding some util method that make it easier to send response, it uses the builder pattern to build the response before sending it to the client, check
BodyParsermiddleware that parse the request body by listening to the
dataevent and keep concatinating the incomming buffer chunks until the
endevent fires, then it will call the next middleware after adding the
bodyobject to the
req, so later we can access the body in our…