New to Node.js and Heroku, recently got it set up and working with a basic hello world, but now I'm trying to get Node.js to display an HTML file, and am having issues. Here's my single JS file:
web.js
var express = require('express');
var app = express();
app.set('views', __dirname + '/views');
app.engine('html', require('ejs').renderFile);
app.get('/', function(req, res) {
res.render('about.html');
});
var port = Number(process.env.PORT || 5000);
app.listen(port, function() {
console.log("Listening on " + port);
});
My HTML file is in '/views', and just displays basic text/title, and works FINE when running 'node web.js'. However, when uploading to Heroku and visiting my site, I get the following error:
Error: Failed to lookup view "about.html" in views directory "/app/views" at Function.app.render (/app/node_modules/express/lib/application.js:508:17) at ServerResponse.res.render (/app/node_modules/express/lib/response.js:782:7) at Object.handle (/app/web.js:9:6) at next_layer (/app/node_modules/express/lib/router/route.js:103:13) at Route.dispatch (/app/node_modules/express/lib/router/route.js:107:5) at /app/node_modules/express/lib/router/index.js:213:24 at Function.proto.process_params (/app/node_modules/express/lib/router/index.js:284:12) at next (/app/node_modules/express/lib/router/index.js:207:19) at Layer.expressInit [as handle] (/app/node_modules/express/lib/middleware/init.js:23:5) at trim_prefix (/app/node_modules/express/lib/router/index.js:252:17)
I'm confused by it saying '/apps/views', as with the original error, the directory was named '/Views', but I changed it to see if it'd help, to no avail. I don't have an /apps directory, is that something they make?
Anyway, just want to display some simple HTML from a subfolder using Node.js on Heroku. Any help is appreciated.
package.jsoncorrect? To test, try pulling the git repo (or moving all files except for thenode_modulesfolder) on a different machine/environment and runningnpm installfollowed bynode web.js