Config Router

  • Google Sheets
  • CCNA Online training
    • CCNA
  • CISCO Lab Guides
    • CCNA Security Lab Manual With Solutions
    • CCNP Route Lab Manual with Solutions
    • CCNP Switch Lab Manual with Solutions
  • Juniper
  • Linux
  • DevOps Tutorials
  • Python Array
You are here: Home / Error: No default engine was specified and no extension was provided

Error: No default engine was specified and no extension was provided

August 1, 2021 by James Palmer

The res.render stuff will throw an error if you’re not using a view engine.
If you just want to serve json replace the res.render(‘error’, { error: err }); lines in your code with:
res.json({ error: err })

PS: People usually also have message in the returned object:
res.status(err.status || 500);
res.json({
message: err.message,
error: err
});

You are missing the view engine, for example use jade:
change your
app.set(‘view engine’, ‘html’);

with
app.set(‘view engine’, ‘jade’);

If you want use a html friendly syntax use instead ejs
app.engine(‘html’, require(‘ejs’).renderFile);
app.set(‘view engine’, ‘html’);

EDIT
As you can read from view.js Express View Module
module.exports = View;

/**
* Initialize a new `View` with the given `name`.
*
* Options:
*
* – `defaultEngine` the default template engine name
* – `engines` template engine require() cache
* – `root` root path for view lookup
*
* @param {String} name
* @param {Object} options
* @api private
*/

function View(name, options) {
options = options || {};
this.name = name;
this.root = options.root;
var engines = options.engines;
this.defaultEngine = options.defaultEngine;
var ext = this.ext = extname(name);
if (!ext && !this.defaultEngine) throw new Error(‘No default engine was specified and no extension was provided.’);
if (!ext) name += (ext = this.ext = (‘.’ != this.defaultEngine[0] ? ‘.’ : ”) + this.defaultEngine);
this.engine = engines[ext] || (engines[ext] = require(ext.slice(1)).__express);
this.path = this.lookup(name);
}

You must have installed a default engine
Express search default layout view by program.template as you can read below:
mkdir(path + ‘/views’, function(){
switch (program.template) {
case ‘ejs’:
write(path + ‘/views/index.ejs’, ejsIndex);
break;
case ‘jade’:
write(path + ‘/views/layout.jade’, jadeLayout);
write(path + ‘/views/index.jade’, jadeIndex);
break;
case ‘jshtml’:
write(path + ‘/views/layout.jshtml’, jshtmlLayout);
write(path + ‘/views/index.jshtml’, jshtmlIndex);
break;
case ‘hjs’:
write(path + ‘/views/index.hjs’, hoganIndex);
break;

}
});

and as you can read below:
program.template = ‘jade’;
if (program.ejs) program.template = ‘ejs’;
if (program.jshtml) program.template = ‘jshtml’;
if (program.hogan) program.template = ‘hjs’;

the default view engine is jade

Related

Filed Under: Uncategorized

Recent Posts

  • How do I give user access to Jenkins?
  • What is docker volume command?
  • What is the date format in Unix?
  • What is the difference between ARG and ENV Docker?
  • What is rsync command Linux?
  • How to Add Music to Snapchat 2021 Android? | How to Search, Add, Share Songs on Snapchat Story?
  • How to Enable Snapchat Notifications for Android & iPhone? | Steps to Turn on Snapchat Bitmoji Notification
  • Easy Methods to Fix Snapchat Camera Not Working Black Screen Issue | Reasons & Troubleshooting Tips to Solve Snapchat Camera Problems
  • Detailed Procedure for How to Update Snapchat on iOS 14 for Free
  • What is Snapchat Spotlight Feature? How to Make a Spotlight on Snapchat?
  • Snapchat Hack Tutorial 2021: Can I hack a Snapchat Account without them knowing?

Copyright © 2025 · News Pro Theme on Genesis Framework · WordPress · Log in