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:
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 [email protected]
npm install ejs
. The meat:
views
and partials
should have the extension .ejsapp.render()
function
You 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 it
res.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.
Support for EJS has been removed from Express v. 3. I've built another example using Express 3 and Jade templates:
https://github.com/nosolopau/node-up-and-running-chirpie-express-3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With