Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make an Express site without a template engine?

Tags:

express

I do not want Jade or EJS on my site. How can I create an express site without it defaulting to the Jade templates? Thanks

like image 810
Matt Hintzke Avatar asked Feb 04 '13 06:02

Matt Hintzke


People also ask

Is Express a template engine?

Luckily, Express. js provides us a way to create dynamic HTML pages from our server-side applications through a template engine. A template engine works in a rather simple manner: you create a template and, with the appropriate syntax, pass variables into it.

Why do we need template engine?

A template engine enables you to use static template files in your application. At runtime, the template engine replaces variables in a template file with actual values, and transforms the template into an HTML file sent to the client. This approach makes it easier to design an HTML page.

Which one is 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.

What are some other template engines?

Popular template engines The popular ones include Ejs, Jade, Pug, Mustache, HandlebarsJS, Jinja2, and Blade.


1 Answers

If what you want is directly to serve static html files with the possibility to cache resources, while still being able to hit "/" and get index.html, then the answer is as easy as this:

var express = require('express'); var http = require('http'); var app = express();  app.use(express.static(__dirname + '/public'));  http.createServer(app).listen(3000); 

Gotcha: Html files including index.html must be inside /public folder instead of /views

like image 64
HeberLZ Avatar answered Nov 25 '22 22:11

HeberLZ