user3822370 user3822370 - 7 months ago 26
HTML Question

Basic html engine in Node

I want to write my HTML in HTML. Not some fancy way. The only thing that would be cool is to be able to use some sort of

include
statement to include header/navigation/footer for each page.

I've looked at pug, ejs, mustache, nunchuck, etc etc. I hate all of these things. I just want to write HTML..

What is a simple node module to do this? And how do I set up the render engine in my main
app.js
? I am using
express

Answer

You can just set up your express routes to connect with html pages. Here's a simple example:

var express = require('express');

// Create express app
var app = express();

// Route index page to an index html page
app.get('/', function(req, res){
  res.sendFile(__dirname  + '/path/to/views/index.html');
});

// Create server
app.listen(8080, function(){
    console.log('Ready on port 8080...');
});

As a side note, ejs is basically html but with some bonus functionality. You can totally get away with writing only html in ejs pages and then start using the ejs features when you get comfortable with it.

Comments