I'm trying to setup Consolidate with node(express v3.1.0), to use Swig. I keep getting the error
Error: Cannot find module 'swig' at Function.Module._resolveFilename (module.js:338:15) at Function.Module._load (module.js:280:25) at Module.require (module.js:362:17) at require (module.js:378:17) at Function.exports.swig.render (/home/jamie/node_modules/consolidate/lib/consolidate.js:237:50) at /home/jamie/node_modules/consolidate/lib/consolidate.js:144:25 at /home/jamie/node_modules/consolidate/lib/consolidate.js:97:5 at fs.readFile (fs.js:176:14) at Object.oncomplete (fs.js:297:15)
At the top, I set it up 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 like this:
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, the console.log(cons.swig) does return something.
{ [Function] render: [Function] }
So its definitely there
Did you install the swig
package? From the readme:
NOTE: you must still install the engines you wish to use, add them to your package.json dependencies.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With