Monday 31 August 2020

First node project - need help with structure

I’ve been stuck on the same issue for a couple of days. It appears to be an design / structure issue.Am building a Survey Web application with node js/ express. It is essentially a learning exercise for me with basic CRUD operations.Some Context - the survey has n questions (say 10) - once the user answers a question, I then display the next question and so on - when the page first loads I have to somehow know that I have 10 questions in the survey and then I have to get the first question. -The only way I can workout how to do this is via a Module embedded in my HTML. The module does a Get API call and returns 10. - I then do a second GET to retrieve the first question. - the only way I can work out how to display my main HTML is by calling a function from the module called generateHTML() and I send through the survey question data and the total number of questions.The issue is that I don’t know how to persist the “10” outside of the module so that I can access it from my JS file .Basically my front end needs to know how many questions are in the survey and the current question , the next question , the last question etc. Am struggling to work out how to store these as global variables.As soon as I move on to building the second question , I no longer have access to the module as it is only called once .What is the appropriate way to manage user state in a JavaScript application ?All the CRUD examples I come across seem to avoid this by choosing examples such as maintaining master data - rather than an actual web application .

Submitted August 31, 2020 at 02:27PM by PuffOca

No comments:

Post a Comment