0.1.1 • Published 8 years ago
connect-ejs v0.1.1
node-connect-ejs
A Middleware for connect to parse ejs files
var documentRoot = __dirname + '/web';
var tplParams = { fromApp : "Hello world" };
var app = require('connect')();
app.use( require('connect-ejs')( documentRoot, tplParams, { indexPage : 'index.ejs', ext : 'ejs' } ) );
var server = require('http').createServer(app);
server.listen(1399);Getting Started
Install node-connect-ejs
$ npm install connect-ejsAdd middleware
Add to connect definition code:
var documentRoot = __dirname + '/web';
var tplParams = { fromApp : "Hello World" };
app.use( require('connect-ejs')( documentRoot, tplParams ) );Create folder in your project name web and create file index.ejs in it.
Insert into web/index.ejs:
<html>
<body>
<%= fromApp %>
</body>
</html>Run your server and test it. Out will be:
<html>
<body>
Hello World
</body>
</html>Variables
ejsmiddlware( documentRoot, tplParams, opts );
documentRoot
Is folder which all your ejs files exists
tplParams
All variables that passing to your ejs file. It can be function ( params are same as in middleware req,res,next )
opts
options of middleware:
indexPage- index page for every folder. Default isindex.ejsext- extension of ejs files. Default isejs
Errors
Errors using console.error and firing when problems in documentRoot. If error happens, server stops. Using process.exit();:
!!! ERROR: No Document root- when you not sets documentRoot!!! ERROR: Document root doesn't exists- folder documentRoot doesn't exists