Question

I've been developing a cloud based server in node.js, and have really enjoyed working with server-side javascript.

I'm writing a mobile app next which will interact with the server.

My question is : How should the client/server interaction work when node.js forces you to program asynchronously?

For example, let's say the user wants to login, and a post request is sent to my node.js server - is it best practice to keep the connection open somehow whilst node does its thing? I'm unsure how an anonymous function in a callback for example would be able to send a response back (especially if the context is lost).

OR would you have the server send back an 'OK (I'm working on it)' and then somehow push to the client when ready?

Sorry for the generalities.. As you all know node likes to accept callback functions whenever waiting is involved (Eg/ database call), and I'm still new to this kind of working.

Thanks!

No correct solution

OTHER TIPS

These details are interesting only if you're implementing a HTTP server from scratch. If you're just looking to create an app which communicates with the server through GET/POST requests, just use the http core module or a framework like Express, you don't need to care about things like keeping the connection alive.

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