I am running a node.js application which upon startup uses fetch
to call an external api (not owned by me) to grab data on a list of devices I own. Once I have this gotten this data from the fetch call I initialise an express server which is located in another file 'server.js' which itself requires an express Router defined in a subfolder 'routes' and mounted on the route '/api'. My question is, the data I initially fetch (which is a javascript object) can be modified by the express server I run, through post requests, and is periodically saved to disk by the primary application. Since the system I am running this on can't handle a database I just use a simple method of saving the data with the fs
module.
What is the best way to architect the flow of data so that the main process which starts the express server can both view and modify the data in the javascript object as well as the post and get routes of the express router being able to have the same privileges?
I tested a rudimentary method where I just passed a reference to the javascript object to the express server and so the original object became the one 'source of truth' that could be modified by both express and non express functions. This felt wrong however and I was wondering if there was any better way of managing this data without using a database?
Via Active questions tagged javascript - Stack Overflow https://ift.tt/Jk789W3
Comments
Post a Comment