Created a simple web app with Express JS that uses MVC architecture. It uses AJAX to send data between the view and the controller, and the code is neatly organized in appropriate areas.
It took me a few days of work just to get data moving between the controller and the view (both JS files, one on the server and one in the browser). I figured out that the best way for me to do it is for the view to send an AJAX POST request (potentially containing user input) to the server, which passes it to the controller. Then the controller updates the model as needed and passes the state of the model to the server, which sends the state to the view as a response to the POST request. The view then manipulates the DOM to update the UI as needed.
I did so many web searches for "how to send data between controller and view with express" or similar, and found nothing related to this approach. Mostly people were passing data to an EJS view when rendering, which is not how I want to do things. I don't want to write my UI logic in EJS markup inside an HTML file, I want to write it in JavaScript in its own file. Frankly EJS just doesn't seem like a good way to perform DOM manipulation to me, but maybe it's there for people who don't want to write a seperate front end.
#webDev #JavaScript #EJS #ExpressJS #NodeJS