Ankit
Ankit

Reputation: 221

How to use EJS in Node.js instead of JADE

I'm trying to create a simple app with express but i want to use EJS instead of JADE. So I do the following:

But when i'm trying to see my web Page through localhost:3000 it shows me an error.

Error: Failed to lookup view "error" in views directory "E:\Express\myApp\views"
   at EventEmitter.render (E:\Express\myApp\node_modules\express\lib\application.js:579:17)
   at ServerResponse.render (E:\Express\myApp\node_modules\express\lib\response.js:961:7)
   at E:\Express\myApp\app.js:53:7 
   at Layer.handle_error (E:\Express\myApp\node_modules\express\lib\router\layer.js:71:5)
   at trim_prefix (E:\Express\myApp\node_modules\express\lib\router\index.js:310:13)
   at E:\Express\myApp\node_modules\express\lib\router\index.js:280:7
   at Function.process_params (E:\Express\myApp\node_modules\express\lib\router\index.js:330:12)
   at IncomingMessage.next (E:\Express\myApp\node_modules\express\lib\router\index.js:271:10)
   at done (E:\Express\myApp\node_modules\express\lib\response.js:956:25)
   at EventEmitter.render (E:\Express\myApp\node_modules\express\lib\application.js:581:14)

Please tell me why it's happening.

Upvotes: 0

Views: 1695

Answers (2)

Rajeev Jayaswal
Rajeev Jayaswal

Reputation: 1501

You could have generated express project with ejs template using following command:

express myApp -e

In you case, you have created express project with jade template and trying to replace jade with ejs everywhere.

There errors you have mentioned are due to nonexistence of file error.ejs in path directory "E:\Express\myApp\views". Please check the path directory "E:\Express\myApp\views" and rename error.jade to error.ejs.

If you face any issues, please post it here.

Upvotes: 1

Daniel Aristizabal
Daniel Aristizabal

Reputation: 349

As the express generator app will create initial layouts and views using Jade, the way to replace with EJS is creating new layouts and basics views on EJS.

The error message said it is unable to find the 'error' view to render. That could be that the file doesn't exist or because it is not a EJS file

update: The express generator command supports --ejs or -e flags to change the view engine when creating a new project

Upvotes: 0

Related Questions