jeudi 2 juillet 2020

Best practice web architechture NodeJS?

First time posting on StackOverflow so, apologies if the question is too open or vague.

I would like to ask about what is considered a best practice for web apps.

First approach:
Have 2 separate servers, a file server to serve static HTML files and these files than would send HTTP requests to the backend and retrieve data from it to display it to the user.

  • In this case, how do you handle dynamic routes like /blog/15184?
  • How are cors handled in this case since you would have two servers running on different ports I assume on a single machine?
  • Finally, how would you restrict access to the node.js backend to be only called from the HTML files on your frontend?

Second approach:
Have a single Node server (I usually use express) handle both rendering files (via ejs as a template engine) and retrieving data from the backend.
In this case,

  • Is better to pass in the data that doesn't need to be updated regularly during the page lifetime when rendering the page or to use HTTP requests.
  • Wouldn't this result in a slower experience with more users since a single server is handling everything?

Is one approach flat-out better than the other? or does it all depend? if so on what factors?

Thank you for taking the time to read this,
I believe this is one of the FAQ's that hobbyists in NodeJS have. So any help would be amazing.




Aucun commentaire:

Enregistrer un commentaire