If I read it correctly, the first set of routes # 1 and # 2 is an API that returns JSON rather than sending it.
Assuming that in # 2 you will not create static pages with JavaScript that make AJAX calls, but rather use express static routing such as app.use('/', express.static(path.join(__dirname, 'dist'))); the difference between the two approaches is not so big.
If you donβt already know any supported template language, for example mustache , then you should study it and choose one before that (which is not always easy from my experience!).
If you donβt know one, depending on your application, you can still learn from the training and use it. As an example, you can come up with a very general interface in which one template could be reused many times - for example, a common database user interface similar to, for example, the well-known phpmyadmin .
In the case of static routing, you can achieve similar results using a JavaScript framework that contains components or templates such as angular . If you do not plan to use it, this can lead to repeated code duplication in other widgets. And even when using one of them, I can imagine a case where the template engine will result in less code (or fewer files in your project, at least). Iβm not sure, although if it will be easier to navigate and, in addition, cover the tests when the project will grow.
Without knowing more about your project, it is difficult to give more advice.
isp-zax
source share