0

I'm a beginner with node.js and i'm trying to build my first web application. However i want to get good practices from the begining.

So I learn some guide to well organize my code. I went on MVC pattern that i understand well. But in the guides I read besides the models, views qnd controllers section there was a middleware section. I can't see the differences between middleware and controllers Here is the guide: http://www.terlici.com/2014/08/25/best-practices-express-structure.html

Can somebody explain me what is the purpsoe of using middlewares precisely, and the difference between middlewares and controllers precisely ?

Thank you in advance.

Termininja
  • 6,620
  • 12
  • 48
  • 49
JimZer
  • 918
  • 2
  • 9
  • 19

1 Answers1

0

The link you provided says it best:

The purpose of a middleware is to extract a common controller code, which should be executed on multiple requests and usually modifies the request and/or the response objects.

So basically, if you have functionality that is shared between controllers you put it in your middleware.

It's explained in more detail here.

Community
  • 1
  • 1
syncdk
  • 2,820
  • 3
  • 25
  • 31