This is in my app.js
app.set('views', path.join(__dirname, 'public')); /I know most app examples seem to use a 'views' directory instead. But I want to put more than views
app.get('/', function(req,res){
res.render('/pages/home');
});
then my folder structure looks like:
package.json
app.js
public
index.html //main html
pages
home.html //one of a few html templates I load in using ngRoute
right now when it starts it gives this error:
Error: Cannot find module '/home/alex/node/pollstut/public/app.js'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
well of course. thats because app.js isn't in public, its in the root directory. I only want it to look for public stuff like html and js in the public directory. I want it to look for app.js in the project root directory. how can I tell it this?
Normal HTML files can be served by using express.static as they do not need a template engine. This will just serve the file without any processing (the same way you serve pictures or text files).
app.use(express.static(__dirname + '/public'));
I believe your error is that you're just setting the views path but you did not specify which engine to use. For example, you could use .ejs or .jade templates. There is an example here.
Also, I see that you're just telling it to render /pages/home without specifying the file extension like you did with index.html.
That error looks like it's generated before your app.js even gets launched. What command are you using to launch your server? My theory is that you are in the pollstut/public directory when you type node app.js. Try cd .. or whatever.
Further, Manuel is correct there- typically stuff in /views is dynamic template stuff, either ejs or jade or whatever other html template language is popular this week. When you call res.render, you're telling express to actually render a template rather than serve it.