With respect to how node.js fits in with clients and web servers, is my description below correct?
- (A) are clients
- (B) is node.js running on some web server
- © are “services” hosting business logic, database access routines, e.g. “GetCustomer()”. For simplicity assume that a service © exposes a REST interface.
So in the flow, the client (A) will request some resource from node.js (B) which will in turn dispatch this request (with all it’s async and evented i/o goodness) to a service © which might go and get some customer information and returns it to node.js (B) via callback and then in turn node.js returns that response to the client.
1.Is this correct?
Two related questions:
2.How does node.js know which service to dispatch a request to? Do you have to create api “stubs” in node.js that mirror the service APIs, since the client isn’t talking directly to the services?
3.How is session state handled in this architecture?
Problem courtesy of: Howiecamp
First of all a “diagram” of the usual flow:
(load balancer e.g. nginx)
| | |
v v V
DB APIS FILES
Concerning your last two questions:
- How do you want it to know that? Node.js is a generic framework you’ll have to write the code to handle this.
- Again, Node.js is completely generic. If you have only one instance you could do it in-memory. Otherwise you’d would likely use redis or the like.
You can write game servers in Node.js, you can just crunch numbers, or you write a web server.
But you don’t have to, do it the way you like or search for a framework that does it the way you like.
Solution courtesy of: Ivo Wetzel