Domanda

Per quanto riguarda il modo Node.JS in sintonia con i client ei server web, è la mia descrizione di seguito è corretto?

  • (A) sono i clienti
  • (B) è node.js in esecuzione su alcuni server web
  • (C) sono i "servizi" che ospitano la logica di business, le routine di accesso al database, per esempio "GetCustomer ()". Per semplicità si assume che un servizio (C) espone un'interfaccia REST.

Quindi, nel flusso, il cliente (A) richiederà qualche risorsa da node.js (B) che a sua volta la spedizione questa richiesta (con tutti i suoi asincrona e ho evented / o bontà) per un servizio (C), che potrebbe andare a prendere un po 'di informazioni sui clienti e lo restituisce al node.js (B), tramite callback e poi a sua volta Node.JS rendimenti che risposta al client.

1.Is corretto?

Due questioni correlate:

2.How fa node.js sapere quale servizio di inviare una richiesta di? Avete creare api "stub" in node.js che rispecchiano le API di servizio, in quanto il cliente non sta parlando direttamente ai servizi?

3.How è stato della sessione gestita in questa architettura?

È stato utile?

Soluzione

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.

Altri suggerimenti

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top