EJS errors: not defined; cannot find module 'undefined'; cannot find module 'ejs'; body is not defined

I was very upset with the "Let build twitter" node app in chapter 2 in O'Reilly's book "Node.js Up And Running".

I have never used EJS and I don’t even know which extension should be used for EJS files. Also, I cannot get my application to work with these various errors:

  • partial not defined
  • Unable to find module 'undefined' where app.render ('index' ... is executed
  • Unable to find module 'ejs' Body
  • undefined

This is even more frustrating, as this is only chapter 2, and I wonder if it would be preferable to switch to another material ...

+5
source share
6 answers

If you, too, were upset with the Let build twitter programming tutorial in chapter 2 of O'Reilly Up and the working book, here is an addition to make this “application” work.

Prerequisites:

  • For this application to work, make sure you have an Express version <3.x. In fact, in version 3.0 and above, they removed the "partial" support, and now it is template specific. Therefore, do not forget to install version 2.x:npm install express@2.x
  • The book does not contain any information on how to use EJS files. After a little research, to express, to understand and analyze the EJS file, you need to install ... ejs. Installation is fairly simple, just like any other module: npm install ejs.

Meat:

  • views partials .ejs
  • EJS, express EJS app.render() :

(1) EJS , express  app.set('view engine', 'ejs');

res.render('index', ...)

(2) app.render() EJS,

res.render('index.ejs', ...)

, , . Fork .

, .

+10

express @4 , !

+1

O'Reilly Book Node.js Up and Running - 1 = > 2 = > Build Twitter ( Express 3.0 ejs JavaScript node ) : https://github.com/thinkphp/express-tweets

0

express @4 . - , , .

, Ningappa

-1

All Articles