Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Can Node.js continue running process after user closes the browser?

Can Node.js continue running process after user closes the browser?

Problem

I am logging some analytics data based on people clicking on my site. When a person clicks on something, it sends a call to my node application via an ajax call, but if what they clicked is an external link, the original request gets cancelled since they leave the site. Is there a good way for node to process the request even after the client has disconnected?

Problem courtesy of: Clint

Solution

It definitely wouldn't matter if the Running process does not need to write things to the response.
Even then, it probably doesn't matter anyway if you do something like

  1. User submits request, you respond "thanx, the job was started". Before you respond, asynchronously execute the job (not hard given that node.js code should be asynchronous to begin with).

  2. Job puts data in some table or file or nosql store.

  3. User can go to a different url to see a list of jobs and their states (started, running, complete) and view results.

Solution courtesy of: hvgotcodes

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Can Node.js continue running process after user closes the browser?

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×