I’ve been very frustrated with the “Let’s build twitter” node app at Chapter 2 in the O’Reilly book “Node.js Up And Running”.
I’ve never used EJS and don’t even know what extension to put for EJS files. Plus, I can’t get my app working getting these various errors:
- partial is not defined
- Cannot find module ‘undefined’ where doing app.render(‘index’…
- Cannot find module ‘ejs’
- body is not defined
It’s even more frustrating since it’s only the Chapter 2 and I’m wondering if it wouldn’t be preferable to switch to another material…
If you too have been frustrated with the “Let’s build twitter” programming tutorial at the Chapter 2 in the O’Reilly Up and running book, here is the complement to make this “app” work.
Pre-requisites:
npm install express@2.xThe installation is pretty straightforward like any other module:
npm install ejs.The meat:
viewsandpartialsshould have the extension .ejsapp.render()functionYou have two ways to do it:
(1) You set EJS as the default template engine and then just tell express to render your file
app.set('view engine', 'ejs');res.render('index', ...)(2) You just tell to the
app.render()function to use EJS, express will take care of itres.render('index.ejs', ...)If at that point it doesn’t work or it’s still not clear, nothing is better than looking at working code. Fork or download the app here.
Hope it helps other readers.