In the world of web development, Node/Express serves as a powerful backend tool while your browser, where vanilla JS operates, functions as the front end.
The backend has the capability to generate output in various formats such as HTML, JSON, XML, or plain text. However, similar to how we cannot alter the value returned by a function, once the backend produces something, it cannot be changed.
On the other hand, frontend tools like vanilla JS are utilized to manipulate the DOM dynamically.
One approach is to retrieve a new resource entirely from the backend. Alternatively, a more efficient method would be to fetch only the specific data you need to modify by establishing a REST API on the same backend.
For instance, you might create a route like /page/quotes
that delivers an HTML page and another route like /api/random_quote
that provides a random quote in JSON format. This can be accessed from frontend JS using methods like fetch