0

I am new to Node.js, but I wanted to start a new project and thought could be a good chance to learn the Node-Express framework and the MEAN stack.

What I'm confused about is why Express comes with the Jade template (*see EDIT) engine if the above mentioned stack uses, by definition, Angular. In fact, it is my understanding that although Jade could be used together with angular, this would be probably unnecessary and might just over-complicate things (see for example this question).

Of course I can see that Express could be used independently of such stack, so maybe let me put the question in a different way.

If it is true that it's not really necessary to combine Jade and Angular, what is the best way to go when building a web app in the MEAN stack framework?

Basically, what is the best way to go if one, after generating an express app using the Jade template, decides that he would like to use Angular (and Mongo)? So in case one started using the Jade template, would it be better to go back to plain HTML in order to use Angular?

It is probably just my ignorance in the field making me confused but some clarifications would be much appreciated.

EDIT: The original title was "Why does Express come with Jade if the MEAN stack uses Angular?" but thanks to the comments I realize that it's really not correct to say that Express "comes" with Jade so I changed the title as I was actually interested mostly in something else after all.

Tommy
  • 628
  • 11
  • 22
  • well, not everyone using Express uses the whole MEAN stack – Kai Jul 14 '17 at 02:16
  • 1
    There are no template engines shipped *with Express*. – mscdex Jul 14 '17 at 02:16
  • MEAN stack is simply a configuration of technologies. Angular is a front-end javascript framework for building single page applications, Express is a web-server library that can render HTML, and if you don't want to write raw HTML you can use Jade which is a rendering engine to construct raw HTML pages from a different markup with added features. – Michael Lyons Jul 14 '17 at 02:17
  • @Kai yes, that's why I wrote " I can obviously see that Express could be used independently of such stack". Maybe my question is better re-phrased in the end of my post. – Tommy Jul 14 '17 at 02:17
  • @MichaelLyons yes I understand that. Maybe my title could be changed to better reflect my question (I believe it's clearer around the end of the post), any suggestions? – Tommy Jul 14 '17 at 02:19
  • @Tommy Depends on what build tools you're using for Angular. You could use Jade (isn't it called Pug now?) to build the HTML page that will host your single page app. Have you gone through a basic MEAN stack tutorial? – Michael Lyons Jul 14 '17 at 02:25
  • @MichaelLyons well I was mostly confused about what to do in case one wants to do a transition from a simple express app (with Jade) to using the full MEAN stack. If you see the question I linked, it seems that Jade and Angular could be used together but that seems unnecessary and maybe make things overly complicated.. so what would be best? Making Jade and Angular work together anyway? Go back to plain HTML first? Is what I mean clearer now? (Yeah it's called Pug now) – Tommy Jul 14 '17 at 02:32

1 Answers1

2

Your whole question seems to be based on a piece of misinformation which makes it hard to answer. Express does not come with Jade. In fact, it does not come with ANY template engines. There are lots of different template engines you can use and all of them must be installed before you can use them with Express. Express comes with a framework for plugging in a template engine, but no actual working template engine.

In fact, Express is specifically designed to be a "Fast, unopinionated, minimalist web framework for Node.js" (those words taken right from their home page). "unopinionated" means that it doesn't come bundled with any particular solution for templates.

Perhaps one source of confusion here is that the Express application generator uses Jade as a default. The Express framework itself does not assume any particular template engine.

These two references may help you understand how template engines are registered and used in Express: Using template engines with Express and res.render() documentation.

MEAN is one particular acronym for one particular stack of technology you can use together. It is by no means the only way to use Express.

node.js template engines are server-side ways of building dynamic web pages. A template exists on the server, node.js then combines some data, the template and a template engine to create an HTML page that can then be delivered to a browser and rendered by the browser. Angular is a client-side engine for also building dynamic pages (typically pages with data inserted into them). It is often used for single page apps. I'd suggest you read What is AngularJS for more details.

So, what you appear to be confused about is two different architectural approaches for building dynamic web pages. The Angular approach is only one way to do things and Express doesn't really care whether you do it the Angular way or some other way. It can do it's job in either scenario.

jfriend00
  • 683,504
  • 96
  • 985
  • 979
  • Understood, thanks for the clarification. That certainly helps. However, in the last part of my post I also ask in case one generated an app using express and Jade, what is the best way to go in case one would like to use the full MEAN stack given that it seems (see linked post) that using Angular AND Jade is unnecessary? – Tommy Jul 14 '17 at 02:28
  • 1
    @Tommy - AngularJS is a particular way of building web pages that have data filled into them somewhat automatically by the framework. It is a client-side technology (data is inserted into the DOM in the browser). Jade and other template engines you would use with nodejs are server-side technologies (though some template engines can also be used on the client-side) for building dynamic web pages on the server. There could actually be some reasons for using both together, though typically one would select one approach of the other. They are different design patterns. – jfriend00 Jul 14 '17 at 02:32
  • I see, so basically what you're saying is that it all (obviously) boils down just to have a clear design idea at the start and build everything in that direction. I guess there is just so much stuff out there that it makes it even more difficult every time one tries to wander into unknown waters. – Tommy Jul 14 '17 at 02:36
  • @Tommy - See what else I added to my answer. If you read the [What is AngularJS](https://docs.angularjs.org/guide/introduction) link I've provided, there are several sections that might help you decide if Angular is appropriate for your project or not. By its own admission, it is "opinionated" about a bunch of things and that makes it suited for only certain types of apps. Express is broader and more flexible and can even serve as the back-end behind an AngularJS driven front-end or can be used with completely different strategies. – jfriend00 Jul 14 '17 at 02:40
  • 1
    @Tommy - Personally, I would probably start with Express and whatever your favorite template engine and database is and get things up and running. You have a lot to learn. Then, once you have the first version of things up and running (with just a few pages), you can explore AngularJS and see if the way it does things it seems appropriate for what you're trying to build. Because you only have a few pages, you won't have spent a lot of time on the template engine stuff, but will have a much better idea how the overall back-end works. – jfriend00 Jul 14 '17 at 02:43
  • Thanks for updating the answer, I will definitely have a look at the links. I agree, and indeed I have already something up and running with Express and Jade. Maybe I got confused saying that Jade "comes with" Express because I probably used express generator to create the skeleton of the app (and I think that "comes" with Jade/Pug). Anyway I updated my title as probably the better question is how to transition to Angular (in case one wishes to do so) when already using the Jade template. – Tommy Jul 14 '17 at 02:48