Where is node.js located in the client web server thread & # 8596; ?

Regarding how node.js is suitable for clients and web servers, is my description below correct?

  • (A) are customers
  • (B) node.js running on some kind of web server
  • (C) - these are the β€œservices” in which the business logic is located, database access procedures, for example. "GetCustomer ()". For simplicity, suppose service (C) provides a REST interface.

Thus, in the thread, the client (A) will request some resource from node.js (B), which, in turn, will send this request (with all its asynchronous messages and events) to the service (C), which can go and receive some information about the client and return it to node.js (B) via a callback, and then, in turn, node.js returns a response to the client.

1. Is this right?

Two related questions:

2. How does node.js know which service is sending the request? Do you need to create api stubs in node.js that reflect the service APIs as the client does not speak directly with the services?

3. How is session state handled in this architecture?

sqi2j.png

+3
source share
2 answers

First of all, the "diagram" of a regular flow:

     Client                                
       |                                    
       v                                    
     Request                               
       |                                  
       v                                                          
(load balancer e.g. nginx)                
       |                                  
       v                                    
 Node.js Instance                          
 |     |      |                             
 v     v      V                            
DB    APIS   FILES                         

Regarding your last two questions:

  • How do you want to know that? Node.js is the general structure you will have to write for this code.

  • Again, Node.js is completely general. If you have only one instance, you can do this in memory. Otherwise, you are likely to use redis or the like.

Node.js, -.

, , , , .

+7

Node.js - javascript, -. - -. (B) Node.js -, - (apache). (C) Node.js, Node.js - . .

2, , . , , .

3, /, .

+2

Source: https://habr.com/ru/post/1787800/


All Articles