I am trying to configure Consolidate using node (express v3.1.0) to use Swig. I keep getting an error
Error: cannot find module 'swig' in Function.Module._resolveFilename (module.js: 338: 15) in Function.Module._load (module.js: 280: 25) on Module.require (module.js: 362: 17) on demand (module.js: 378: 17) in Function.exports.swig.render (/ home / jamie / node_modules / consolidate / lib / consolidate.js: 237: 50) to / home / jamie / node_modules / consolidate /lib/consolidate.js:144:25 on / home / jamie / node_modules / consolidate / lib / consolidate.js: 97: 5 on fs.readFile (fs.js: 176: 14) in Object.oncomplete (fs.js : 297: 15)
At the top, I installed it like this:
var express = require('express'); var cons = require('consolidate'); // assign the swig engine to .html files console.log(cons.swig); app.engine('html', cons.swig); // set .html as the default extension app.set('view engine', 'html'); app.set('views', __dirname + '/views');
then I make my request as follows:
app.get('/', function(req, res){ res.render('home', { title: "home" }); });
I have a template, home.html, in the root directory / views
My root directory is / home / jamie / hello -world. What am I doing wrong here?
Edit By the way, console.log (cons.swig) is really returning something.
{ [Function] render: [Function] }
So its definitely there
Jameo
source share