Sergi
Sergi

Reputation: 1240

Express Application Architecture, templating engine or isolated API

I have built a Rest-API with Express and mongoose, now it's time to connect it to a Frontend and I am bit confused, I have started building the Frontend of the app with hbs as the templating engine and that works well but I was also considering React for example and that brings me to my question.

What is the best solution here? to build the whole App in one folder so to speak, with a templating engine taking care of the Frontend or to create the API, host it and then use it with a Frontend application? It is a matter of preference or one is better than the other?

Upvotes: 0

Views: 30

Answers (1)

Noah Prail
Noah Prail

Reputation: 647

This really is a matter of preference. There are many benefits and trade-offs for each method. Here are some:

API with Single-Page Application

Benefits

  • Easier to make a more dynamic app
  • With an API you can allow third-parties to integrate with your app easily
  • Fast - after the app has been initially downloaded only data needs to be transferred!
  • API and frontend separation can help keep business logic in one place (on the backend)
  • Offline and caching are easy!

Downsides

  • SEO isn't as easy (but still very much possible)
  • Slow - if your app is big, the initial download speed can be slow (there are lots of solutions for this)

Multi-Page Application

Benefits

  • Fast (page download can be faster)
  • SEO is slightly easier
  • More secure by default (due to cross-site scripting on SPAs)

Downsides

  • Slow - unlike a SPA, you have to download every page
  • Harder to build and debug

This is by no means a comprehensive list of trade-offs but hopefully, it will help you make an informed decision. Personally, I prefer the SPA approach because I have multiple sites/apps using one backend as well as the ease of development.

Upvotes: 1

Related Questions