Tuesday, 22 September 2020

Runtime Context in Nodejs

I've recently learned node and I have been testing and learning with side project for over 3 months now but I have I question :I've come from a Java background so in Java we used to make a Runtime Context based on the Thread.id of the request , the Runtime Context will hold all of the global data for the request like the current user that is authorized in this request or the current user IP or some other parameters so we don't want to deep pass those parameters along the functions calls or in some cases we can't deep pass themSince node is single threaded , we don't have a unique identifier for each request to build the Runtime context on so I found cls-rtracer library that will give each request a unique id and that solved my problemBUT I have a few questionsAm I thinking wrong ? what do you guys use to store global information about the request that are accessible everywhere ?Dose anyone tried cls-rtracer before ? Is it reliable even after load ? , Dose it have a huge impact on performance ?A simple example of why I would need a Runtime Context and I can't even deep pass the parametersI'm using Sequelize as an ORM and I should log each operation that happens on the database through Sequelize hooks , so every time a hook gets called I get the current user and the current user ip from the Runtime contextwaiting for your opinions ..

Submitted September 22, 2020 at 02:41PM by A_HM

No comments:

Post a Comment