Skip to content
Advertisement

Express Js EJS Layouts Error: No default engine was specified and no extension was provided

Hi I am trying to use Express EJS Layouts in my app. As soon as I try to app.use(expressEjsLayouts) it throws an error. Without it the application works perfectly fine but I’d like to make use of ExpressEjs-Layouts for my templates. Please be kind I am fairly new to coding 🙂 I’ve looked through many posts already but couldnt find an answer. Here is my server.js

JavaScript

This is the error:

JavaScript

Advertisement

Answer

You need to tell express which view engine you’re using. You can do it by using the app.set() method. it takes two parameters 1.what you’re setting. in this case a view engine 2.the type of view engine you wish to use

e.g app.set('view engine', 'ejs'); or app.set('view engine', 'pug');

Here is the documentation https://expressjs.com/en/guide/using-template-engines.html

Advertisement