Question

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
  • (C) are "services" hosting business logic, database access routines, e.g. "GetCustomer()". For simplicity assume that a service (C) 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 (C) 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?

Was it helpful?

Solution

First of all a "diagram" of the usual flow:

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

Concerning your last two questions:

  1. How do you want it to know that? Node.js is a generic framework you'll have to write the code to handle this.

  2. 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.

OTHER TIPS

Node.js is a framework for writing applications in javascript that don't run in a web browser. Because of its async nature it happens to be really good at writing web services. For (B) Node.js is the webserver, it doesn't run inside a webserver (apache). For (C) all of your logic can just be in your Node.js app or, your Node.js app can talk to some other service to get data. It is totally up to you.

For 2, you can do it how ever you want. You are writing the code, do it the way that makes sense in your app.

For 3, state is handled by a session/connection object being passed around to the callbacks.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top