Home > Article > Backend Development > javascript - In web development, what does it mean to use node as middleware and php as backend?
I often hear people say that node is used as middleware. Aren’t these two backgrounds?
I often hear people say that node is used as middleware. Aren’t these two backgrounds?
node.js can also write servers
You can use nodejs to set up routing, request interfaces, and render pages. This is more conducive to SEO and has better security than conventional ajax requests. (PS: personal opinion)
Node as a middleware originated from a way to separate the front and back ends. Its role here is to allow the front end to control the Controller and view. If node is not used as a middleware, then the front end needs to learn PHP, which is costly. , if you connect to node, it will become very natural for the front end.
Of course, having an extra layer means a certain performance loss, but it is still possible to separate responsibilities in more detail
For more details, please read some articles on Taobao’s front-end and back-end separation
Node serves as the middle layer, which means that the front-end project is an independent service. Routing control and image rendering are all completed independently under this service and do not depend on other services.
Since it is the middle layer, there must be a real back-end service. This back-end service is an API service and can be implemented in any language.
Front-end services and back-end services are mainly connected by ajax requests. The data required in the view is obtained from the backend service through an ajax request and then presented.
Recommend an article https://github.com/hanzichi/u...
"Front-end" and "back-end" have different meanings in different contexts. They are both "server" and you can also distinguish between front and back ends
Reference https://segmentfault.com/q/10...
By the way, "backend" should generally be referred to as "management backend", "operation backend", etc. It is different from "frontend": "main site" and "user main site". It is a difference between the users, not a technical difference
Isn’t this the separation of front and back ends? . .
Middleware, there is a word in Chinese rhetoric method called Connecting the past and connecting the following
.
Correspondence here to understand. Node takes over the front-end and starts the back-end. To understand this, first understand how the web
side operates. The user clicks on a place and submits it to the backend (PHP
) through node
, and then obtains the corresponding data through database operations, and then renders it to the page through node
. It's like creating a middle layer, as mentioned above, in order to separate the front and back ends and make the responsibilities of each position clearer.
Take the small system I wrote myself as an example. I use html+nodejs+socket.io on the front end to implement a real-time chat system. Then nodejs uses an http request to request the PHP interface to save what the user sent. This way the PHP interface is completely independent. Nodejs is middleware (of course node can also directly operate the database).