I am trying to render a static HTML page when a GET request is made to the root directory (/).
However, I receive the following error when accessing the root directory (http://localhost:3000/):
TypeError: Cannot read property '_locals' of undefined
Project Structure
index.js
node_modules
public
|-- html
| |--index.html
index.js
var express = require('express');
var app = express();
var port = 3000;
app.use(express.static(__dirname + '/public'));
app.listen(port);
console.log('Server running on port ' + port + '.');
app.get('/', function(req, res) {
app.render(__dirname + '/html/index.html');
})
I can access my static HTML page by going to http://localhost:3000/html/index.html. However, calls to app.render() fail. I suspect it has something to do with the directory I am passing into app.render().
res.sendFileinstead ofapp.render. I thinkexpressis to renderhtmlfiles directly.