I have a basic node.js app that I am trying to get off the ground using Express framework. I have a views
folder where I have an index.html
file. But I receive the following error when loading the web browser.
Error: Cannot find module 'html'
Below is my code.
var express = require('express');
var app = express.createServer();
app.use(express.staticProvider(__dirname + '/public'));
app.get('/', function(req, res) {
res.render('index.html');
});
app.listen(8080, '127.0.0.1')
What am I missing here?
You can have jade include a plain HTML page:
in views/index.jade
in views/plain.html
and app.js can still just render jade:
If you're using express@~3.0.0 change the line below from your example:
to something like this:
I made it as described on express api page and it works like charm. With that setup you don't have to write additional code so it becomes easy enough to use for your micro production or testing.
Full code listed below:
You could also read the html file and send it.
Add the following Lines to your code
Replace "jade" with "ejs" & "X.Y.Z"(version) with "*" in package.json file
Then in your app.js File Add following Code :
app.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');
And Remember Keep All .HTML files in views Folder
Cheers :)
I usually use this
Just be careful because that'll share anything in the /web directory.
I hope it helps
From the Express.js Guide: View Rendering
So either you create your own simple renderer or you just use jade:
More about
app.register
.