javascript - Node asynchronous route code -


I am using node with express 4.0. I can not find anything on the internet about embedding asynchronous code on the way.

It is quite easy with the middleware:

  app '/ Some', function (rick, race, next) {doSomethingAsync (function (mistake, possibly sombeielsay) {// maybe checking some error Next ();});}); The problem with the routes is that there is no  next  callback, how does it show that when it comes to going to the next job? 

  app.get ('/ something', function (rik, ridge) {res.render ('SomeTemplate'); // no next (), but it still works });  

If I had to guess, then I would say that after the above work execution, the express moves for the next job but curiosity has launched the following code ...

< Pre> app.get ('/ something', function (rick, ris, next) {console.log (Next);});

... and actually some next callback has been passed. So what's going on here? How does this work behind the scenes? And how can I enter asynchronous code there?

Express to stop the socket unless you call res.render < / Code> which means that you can pass res.render in a callback that executes x second and everything will still work.

Next Go to the next route, which map your values, you can get a great explanation here:

But what are you asking here? Under it If the render () is called on the res object, the data will be sent and the socket will be closed.


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -