Error: Failed to lookup view in Express

Adding to @mihai’s answer: If you are in Windows, then just concatenating __dirname’ + ‘../public’ will result in wrong directory name (For example: c:\dev\app\module../public). Instead use path, which will work irrespective of the OS: var path = require (‘path’); app.use(express.static(path.join(__dirname + ‘../public’))); path.join will normalize the path separator character and will return correct path value.

Use a variable in a Jade include

AFAIK JADE does not support dynamic including. What I suggest is to “include” outside the template, i.e. app.js app.get(‘/admin’, function (req, res) { var Admin = require(‘./routes/admin/app’).Admin; var page=”admin”; var templates = page + ‘/templates/’; // render template and store the result in html variable res.render(templates, function(err, html) { res.render(Admin.view, { title: ‘Admin’, page: page, … Read more

Accessing Express.js local variables in client side JavaScript

When rendering is done, only the rendered HTML is send to the client. Therefore no variables will be available anymore. What you could do, is instead of writing the object in the input element output the object as rendered JavaScript: script(type=”text/javascript”). var local_data =!{JSON.stringify(data)} EDIT: Apparently Jade requires a dot after the first closing parenthesis.

How can I get Express to output nicely formatted HTML?

In your main app.js or what is in it’s place: Express 4.x if (app.get(‘env’) === ‘development’) { app.locals.pretty = true; } Express 3.x app.configure(‘development’, function(){ app.use(express.errorHandler()); app.locals.pretty = true; }); Express 2.x app.configure(‘development’, function(){ app.use(express.errorHandler()); app.set(‘view options’, { pretty: true }); }); I put the pretty print in development because you’ll want more efficiency with … Read more

Change the “No file chosen”:

Hide the input with css, add a label and assign it to input button. label will be clickable and when clicked, it will fire up the file dialog. <input type=”file” id=”files” class=”hidden”/> <label for=”files”>Select file</label> Then style the label as a button if you want.