Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can express mix html and jade routes?

I want to setup an application where I can write as much html over jade as possible. I don't dislike jade, I just want to write html/angular/node APIs, since I'm learning a lot of technologies at once (angular, node, jade, etc).

I would like to build a skeleton project like the following:

  1. Static (server built pages using jade or html) for SEO (basic business card pages). i.e. sitename.com/about, sitename.com/

  2. angular driven admin area (i.e. sitename.com/admin), that is a single html file with embedded angular views/partials.

Should I just learn jade, or attempt to use this mixed approach? I have the first part (simple jade static pages).

like image 326
user376456 Avatar asked Jun 03 '13 14:06

user376456


People also ask

Which is the best template engine for Express?

Some popular template engines that work with Express are Pug, Mustache, and EJS. The Express application generator uses Jade as its default, but it also supports several others. See Template Engines (Express wiki) for a list of template engines you can use with Express.

What is Jade in Express JS?

Jade is a template engine for node. js and the default rendering engine for the Express web framework. It is a new, simplified language that compiles into HTML and is extremely useful for web developers. Jade is designed primarily for server-side templating in node.

Why use templating engine?

Template engines are used when you want to rapidly build web applications that are split into different components. Templates also enable fast rendering of the server-side data that needs to be passed to the application. For example, you might want to have components such as body, navigation, footer, dashboard, etc.


1 Answers

Express is pretty template-agnostic, in that you can choose any templating engine you like. If you want more HTML-style templates, you could use ejs instead of Jade, for instance:

// install ejs first
npm install ejs
// app.js
var express = require('express');
var app     = express();

app.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');

app.get('/', function(req, res) {
  res.render('index', { name : 'World' });
});

app.listen(3012);
// ./views/index.html
<h1>Hello <%= name %>!</h1>
// Output:
<h1>Hello World!</h1>
like image 150
robertklep Avatar answered Oct 22 '22 23:10

robertklep