Reputation: 9854
I wrote a simple expressjs app that runs just fine locally, and even on no.de, but on Nodester when I access http://myapp.nodester.com/ I get an Internal Server Error
and the logs say
Error: failed to locate view "home"
at Function.compile (/node_modules/express/lib/view.js:58:15)
at ServerResponse._render (/node_modules/express/lib/view.js:416:18)
at ServerResponse.render (/node_modules/express/lib/view.js:317:17)
at Router.<anonymous> (/app/server.js:32:6)
at done (/node_modules/express/lib/router/index.js:250:22)
at middleware (/node_modules/express/lib/router/index.js:244:9)
at param (/node_modules/express/lib/router/index.js:227:11)
at pass (/node_modules/express/lib/router/index.js:232:6)
at Router._dispatch (/node_modules/express/lib/router/index.js:255:4)
at Object.handle (/node_modules/express/lib/router/index.js:45:10)
Error: failed to locate view "home"
at Function.compile (/node_modules/express/lib/view.js:58:15)
at ServerResponse._render (/node_modules/express/lib/view.js:416:18)
at ServerResponse.render (/node_modules/express/lib/view.js:317:17)
at Router.<anonymous> (/app/server.js:32:6)
at done (/node_modules/express/lib/router/index.js:250:22)
at middleware (/node_modules/express/lib/router/index.js:244:9)
at param (/node_modules/express/lib/router/index.js:227:11)
at pass (/node_modules/express/lib/router/index.js:232:6)
at Router._dispatch (/node_modules/express/lib/router/index.js:255:4)
at Object.handle (/node_modules/express/lib/router/index.js:45:10)
Then through the fs module I tried to see why it was not there, and an fs.readdir('.',function(error,files){console.log(files)})
returned this:
[ '.nodester',
'app',
'node_modules',
'usr',
'lib64',
'sbin',
'etc',
'dev',
'proc',
'home',
'bin',
'lib',
'root',
'.PKGINFO',
'.INSTALL' ]
And I also found out that all the files I git push
ed are inside the apps
directory.
Does this mean I must tell express the right path where my views
folder is ? How can I do this ? (I only know how to tell it to render a file in an absolute path).
Upvotes: 1
Views: 1868
Reputation: 2487
Setup views dir manually using built-in variable __dirname
:
var app = module.exports = express.createServer();
app.configure(function(){
...
app.set('views', __dirname + '/views');
app.use(express.static(__dirname + '/public'));
});
Try to generate application skeleton using express
comman-line tool (it's accessible, if you install last express version from npm). It generates good starting point for you.
Upvotes: 2