I recently started using Angular, Node and Express. I have made some working browser-based applications in Angular and am attempting to port them to server applications in Node and Express. (In particular, one will pull data from Twitter and another from Wikidot.)
Since I am using Angular for data injection and templating, I do not want to use another view engine such as EJS or Jade. I want to use the HTML/Angular code that I have already written with as little modification as possible. I'm very confused as to why Express requires me to have a view engine.
What is the simplest way to get this code working as a Node/Express application?
View engines are useful for rendering web pages. There are many view engines available in the market like Mustache, Handlebars, EJS, etc but the most popular among them is EJS which simply stands for Embedded JavaScript. It is a simple templating language/engine that lets its user generate HTML with plain javascript.
View engines allow us to render web pages using template files. These templates are filled with actual data and served to the client. There are multiple view engines, the most popular of which is Embedded Javascript (EJS).
Is a View Engine necessary for Express/Node? No, it is not required. Express can happily serve static HTML5 files as you wish. You don't need a view engine for that.
Though there is a fundamental difference between the way these frameworks are used in developing web applications, for example, Express is primarily used for backend purposes, while Angular is known for frontend capabilities.
Since you're using AngularJS, I don't think you care a lot about Express's view engine, that's e.g. better if you're using Express to render HTML. Maybe you'll just use that to load your initial HTML (with links to all the .js, .css etc) into the browser (server-side template rendering), the rest of the work is done with AngularJS talking to your Express's HTTP service
Simple way is for you to return JSON from Express, try this function http://expressjs.com/api#res.json
Use AngularJS to communicate with Express, AngularJS renders the interesting things on the browser (client-side template rendering, and more)
The answer I was looking for is this line of code.
app.engine('html', require('ejs').renderFile);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With