Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS with Express Templates or pure HTML? Pros and Cons?

Express JS uses templates for generating HTML and then server sends them to client in response. There may be several other templates from which HTML can be generated. The ones I was able to discover are:

  • Jade (http://jade-lang.com/)

  • EJS (http://embeddedjs.com/)

In my app, I need to use both ExpressJS and AngularJs. I am new to both technologies. While learning angular, I had to use it in pure HTML. After learning ExpressJs, I realized, in order to use angularjs, I need to use them in any of the above templates which will be converted to HTML while sending to client.

Now, I want to use expressjs as my server and angularjs as my client side app. For this, I think I have two options.

Option 1

I can stop using templates altogether and use our NodeJS server to respond by sending simple HTML files. These HTML files will then contain AngularJS coding within them. AngularJS then, on client side, will act as our application. It will demand other HTML documents from the server. Or it can also be used like AJAX, where we can only request the piece of information to update just part of the page rather refreshing the whole page for a minor change.

Option 2

I can use angularjs inside expressjs templates (jade or ejs).

Kindly, help me in understanding the pros and cons of both options. Which one will be your choice in such case.

like image 689
Sam Fast Avatar asked Dec 13 '13 15:12

Sam Fast


People also ask

Is Angular better than express?

Conclusion. Angular helps with pre-built plugins that reduce the need for complex third-party integrations. At the same time, Express comes with templates, packages, and plugins, making it an attractive option. In a nutshell, the choice between these two frameworks depends on the specific needs of your project.

Which is better AngularJS or NodeJS?

AngularJS will be the best choice while developing a single-page client-side web application, while Node. js wins while building fast and scalable server-side apps. Node. js is a run-time environment for Apps written in the JavaScript language, whereas, AngularJS is Google's open-source web app development framework.

What is AngularJS How does it work with HTML?

AngularJS extends HTML with ng-directives. The ng-app directive defines an AngularJS application. The ng-model directive binds the value of HTML controls (input, select, textarea) to application data. The ng-bind directive binds application data to the HTML view.


3 Answers

This is very much an opinion question and Stack Overflow admins hate anything that smacks of opinion, but here's my experience and opinion nevertheless.

I've done a couple of apps now using purely static files (HTML, CSS, and JavaScript) with those calling a service on the back-end to deliver the data. It reduces the back-end, whatever it is (I've used both Java and Node.js), to just being a set of service URLs but it works very very well.

  • You've got a fantastic hard line between the responsibilities of the two systems
  • It's very easy to work on and test each one independently
  • Bugs are usually very clearly in the front-end or the back-end (all you have to do is look at the data transferred to know)
  • The back-end services are ready to be reused to support alternative UIs from the command line or something mobile specific if you want
  • You can use one technology for the back-end to start with (say Node.js or Ruby on Rails) and then switch to something else later if you need to. As long as the API stays the same the front-end never knows.
like image 147
John Munsch Avatar answered Oct 31 '22 17:10

John Munsch


I personally use AngularJS with Express/Jade. The setup is actually pretty simple and I find writing Jade much more enjoyable than writing HTML. I've also adopted writing my Angular code in CoffeeScript as, again, it makes for quicker development. If you are looking to save keystrokes then Jade is a great solution and its integration with Express makes it a no brainer. If you aren't worried about producing code more quickly then there is absolutely no problem with using HTML.

I will point out that one of the greatest benefits I have found to using Jade over HTML is the ability to develop a single page in multiple files, then use include to have them concated before compiling into HTML. This allows you to take larger pages and break them into more manageable chunks. Together with Angular's templating, this can relieve much frustration.

Really it is all a matter of opinion, but since I decided to give Jade a shot, I have not regretted it and I have never ran into a situation where my HTML was rendered incorrectly when using Angular.

like image 38
Dan Armstrong Avatar answered Oct 31 '22 17:10

Dan Armstrong


I went with option 1 because I didn't want to deal with any potential issues with jade or ejs converting the template incorrectly and interfering with Angular. My app essentially has the index page (which is really just the basic page template with my css and js includes) come out of Express as jade and then angular takes it come there and all my angular templates are in a separate location than my jade template.

like image 2
Fourth Avatar answered Oct 31 '22 16:10

Fourth