Error with heroku in node: Failed lookup view in views derectory

3

I have a web app that works well in local but when uploading it to heroku the following came out in the logs

2017-01-01T00:30:57.874896+00:00 app[web.1]: Error: Failed to lookup view "notFound" in views directory "/app/views" 2017-01-01T00:30:57.874919+00:00 app[web.1]: at EventEmitter.render (/app/node_modules/express/lib/application.js:579:17) 2017-01-01T00:30:57.874920+00:00 app[web.1]: at ServerResponse.render (/app/node_modules/express/lib/response.js:960:7) 2017-01-01T00:30:57.874921+00:00 app[web.1]: at exports.notFound (/app/routes/index.js:31:7) 2017-01-01T00:30:57.874922+00:00 app[web.1]: at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5) 2017-01-01T00:30:57.874922+00:00 app[web.1]: at next (/app/node_modules/express/lib/router/route.js:131:13) 2017-01-01T00:30:57.874923+00:00 app[web.1]: at Route.dispatch (/app/node_modules/express/lib/router/route.js:112:3) 2017-01-01T00:30:57.874923+00:00 app[web.1]: at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5) 2017-01-01T00:30:57.874924+00:00 app[web.1]: at /app/node_modules/express/lib/router/index.js:277:22 2017-01-01T00:30:57.874924+00:00 app[web.1]: at param (/app/node_modules/express/lib/router/index.js:349:14) 2017-01-01T00:30:57.874925+00:00 app[web.1]: at param (/app/node_modules/express/lib/router/index.js:365:14)

I did a little research and I saw that I had to put this in node's main file

var path = require('path');

app.use(express.static(path.join(__dirname, 'public')));
app.set('views'(path.join(__dirname, 'views')));

But that still did not work for me so I went to the node documentation and found the solution that I share below in case someone has the same problem

    
asked by Mauro Espinosa 01.01.2017 в 02:02
source

1 answer

4

Instead of this:

var path = require('path');

app.use(express.static(path.join(__dirname, 'public')));
app.set('views'(path.join(__dirname, 'views')));

I put this:

var path=require('path');

app.set('views', path.join(process.cwd() + '/views'));
app.use(express.static(path.join(process.cwd() + '/public')));

Besides that my folder for the views was called "Views" and I renamed it to lowercase (views), and it worked correctly

    
answered by 01.01.2017 / 02:02
source