{"id":3589,"date":"2016-04-06T12:33:26","date_gmt":"2016-04-06T12:33:26","guid":{"rendered":"http:\/\/www.garysieling.com\/blog\/?p=3589"},"modified":"2016-04-06T12:33:26","modified_gmt":"2016-04-06T12:33:26","slug":"fixing-express-error-typeerror-engine-not-function","status":"publish","type":"post","link":"https:\/\/www.garysieling.com\/blog\/fixing-express-error-typeerror-engine-not-function\/","title":{"rendered":"Fixing Express Error: TypeError: this.engine is not a function"},"content":{"rendered":"<p>In express.js you can get this error:<\/p>\n<pre>\nTypeError: this.engine is not a function\n<\/pre>\n<p>Typically this is caused by copy-pasting incomplete code from the internet.<\/p>\n<p>To fix it, you need to install a template engine and register it with Node. You also need to ensure your template files have the correct extension.<\/p>\n<p>For example, EJS is popular, and has HTML-like templates:<\/p>\n<pre lang=\"html\">\n<ul>\n<% for(var i=0; i<supplies.length; i++) {%>\n   <li><%= supplies[i] %><\/li>\n<% } %>\n<\/ul>\n<\/pre>\n<p>To make this available, install it from NPM:<\/p>\n<pre lang=\"javascript\">\n$ npm install --save ejs\nnpm WARN package.json image-annotation@1.0.0 No repository field.\nnpm WARN package.json image-annotation@1.0.0 No README data\nejs@2.4.1 node_modules\\ejs\n<\/pre>\n<p>Then register it with express (the first argument is a magic string, and the second argument is how it will &#8216;require&#8217; it)<\/p>\n<pre lang=\"javascript\">\napp.set('view engine', 'ejs');  \n<\/pre>\n<p>Then, make sure you have &#8220;.ejs&#8221; as the file extension (it&#8217;s not clear why this is necessary, since &#8216;view engine&#8217; seems to be a single value):<\/p>\n<pre lang=\"javascript\">\nres.render('search.ejs', output);\n<\/pre>\n<p>You can also require ejs yourself and call it directly, using the instructions in the documentation:<\/p>\n<pre lang=\"javascript\">\nlet ejs = require('ejs');\n\nvar template = ejs.compile(str, options);\ntemplate(data);\n\/\/ => Rendered HTML string \n \nejs.render(str, data, options);\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In express.js you can get this error: TypeError: this.engine is not a function Typically this is caused by copy-pasting incomplete code from the internet. To fix it, you need to install a template engine and register it with Node. You also need to ensure your template files have the correct extension. For example, EJS is &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.garysieling.com\/blog\/fixing-express-error-typeerror-engine-not-function\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Fixing Express Error: TypeError: this.engine is not a function&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[9],"tags":[210,302,387,388,455],"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/3589"}],"collection":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/comments?post=3589"}],"version-history":[{"count":0,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/3589\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/media?parent=3589"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/categories?post=3589"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/tags?post=3589"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}