Render basic HTML view in Node JS Express?


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) {

app.listen(8080, '')

What am I missing here?

By : aherrick


//@Error: Cannot find module 'html'

//.. file is somewhere else!!!

console.log('Current uri: '   uri); // u are lookin for this file
console.log('Current directory: '   process.cwd()); //!!!
By : beom

if you are using express framework to node.js

install npm ejs

then add config file

app.set('port', process.env.PORT || 3000);
app.set('views', __dirname   '/views');
app.set('view engine', 'ejs');
app.set('view engine', 'jade');


render the page from exports module form.js have the html file in the views dir with extension of ejs file name as form.html.ejs

then create the form.js


I usually use this

app.configure(function() {
    app.use(express.static(__dirname   '/web'));

Just be careful because that'll share anything in the /web directory.

I hope it helps

This video can help you solving your question :)
By: admin