Setting a handlebars helper to return a specific value per request in express

I have an express based app serving server side rendered HTML from handlebars templates, and a bundle of the backbone resources. Theoretically, client side, the app resembles what is happening server side.

This is all fine in development, but when the node server is dealing with many requests at the same time, then the mechanism by which the helper we are using is defined/redefined breaks - we set the helper (in this case logged in / not logged in, but could be anything) then serving the rest of the request happens asynchronously - we don't know and cannot control how long this will take.

I have already figured out that this is because Handlebars on the server is effectively a global - so every time a request comes in, the helper that is being called is from there, a shared object between requests.

The question is, how to be able to set a helper per async request that returns that particular value, and does not get polluted by concurrent requests...?

Here's a gist of a test case - hopefully shows the problem:

https://gist.github.com/dazld/023df6e1da7a92387720

(if it is not obvious from that what i am going for, just ping in comments, and i will write up something clearer).

Thanks!

This is because your using a single instance of Handlebars and with lots of requests your polluting one request with another.

I use hbs (https://github.com/donpark/hbs) as it creates a new instance of handlebars for each request/render for you.