0

I have tried to deploy my NodeJs application to IISnode for a few days but i still unable to make it work. I believe i have all the components installed (URL Rewrite Module and IISNode) and just the configuration is wrong. I'm using ejs as a view engine and the browser is throwing an error saying:

ReferenceError: C:\inetpub\wwwroot\Monito\views\layout.ejs:4
   2| <html lang="en" ng-app="app"> 
   3|   <head> 
>> 4|     <title><%= title %></title> 
   5|     <link rel="stylesheet" href="/css/bootstrap.min.css "> 
   6|     <link rel="stylesheet" href="/css/bootstrap-theme.css" > 
   7|     <link rel="stylesheet" href="/css/dashboard.css" > 

title is not defined
   at eval (eval at <anonymous> (C:\inetpub\wwwroot\Monito\node_modules\ejs\lib\ejs.js:299:12), <anonymous>:2:1943)
   at C:\inetpub\wwwroot\Monito\node_modules\ejs\lib\ejs.js:325:14
   at View.exports.renderFile [as engine] (C:\inetpub\wwwroot\Monito\node_modules\ejs\lib\ejs.js:195:31)
   at View.render (C:\inetpub\wwwroot\Monito\node_modules\express\lib\view.js:76:8)
   at Function.app.render (C:\inetpub\wwwroot\Monito\node_modules\express\lib\application.js:527:10)
   at ServerResponse.res.render (C:\inetpub\wwwroot\Monito\node_modules\express\lib\response.js:900:7)
   at C:\inetpub\wwwroot\Monito\node_modules\express-ejs-layouts\lib\express-layouts.js:80:14
   at C:\inetpub\wwwroot\Monito\node_modules\ejs\lib\ejs.js:203:5
   at process._tickCallback (node.js:442:13)

Below are my configurations:

web.config:

<configuration>
  <system.webServer>
    <handlers>
      <add name="iisnode" path="hello.js" verb="*" modules="iisnode" />
    </handlers>
<rewrite>
      <rules>
        <rule name="myapp">
          <match url="/*" />
          <action type="Rewrite" url="hello.js" />
        </rule>
      </rules>
    </rewrite>
   </system.webServer>
</configuration>

Hello.Js:

var debug = require('debug')('Monito');
var app = require('./app');

app.set('port', process.env.PORT || 3000);

var server = app.listen(app.get('port'), function() {
    debug('Express server listening on port ' + server.address().port);
});

index.js:

var express = require('express');
var router = express.Router();
var mongoose = require('mongoose');
var util = require('util');
var Q = require('q');

/* GET home page. */
router.get('/', function (req, res) {
res.render('index', { title: 'Dashboard', layout: 'layout.ejs'});
});

module.exports = router;

package.json

{
  "name": "Monito",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "start": "node hello.js"
  },
  "description": "Monito",
  "author": {
    "name": "tj",
    "email": ""
  },
  "dependencies": {
    "express": "~4.9.0",
    "body-parser": "~1.8.1",
    "cookie-parser": "~1.3.3",
    "morgan": "~1.3.0",
    "serve-favicon": "~2.1.3",
    "debug": "~2.0.0",
    "jade": "~1.6.0",
    "stylus": "0.42.3"
  }
}

App.Js

var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');

var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');

var routes = require('./routes/index');
var users = require('./routes/users');
var detail = require('./routes/detail');
var log = require('./models/log_model');
var mongoose = require('mongoose');
var ejslayout = require('express-ejs-layouts');

mongoose.connect('mongodb://logger:test@127.0.0.1:27017/log');
var app = express();

app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');

app.use(logger('dev'));
app.use(ejslayout);
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(require('stylus').middleware(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, 'public')));

app.use('/', routes);
app.use('/users', users);
app.use('/detail', detail);

// catch 404 and forward to error handler
app.use(function (req, res, next) {
    var err = new Error('Not Found');
    err.status = 404;
    next(err);
});

// error handlers

// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
    app.use(function (err, req, res, next) {
        res.status(err.status || 500);
        res.render('error', {
            message: err.message,
            error: err
        });
    });
}

// production error handler
// no stacktraces leaked to user
app.use(function (err, req, res, next) {
    res.status(err.status || 500);
    res.render('error', {
        message: err.message,
        error: {}
    });
});


module.exports = app;

Folder Structure:

ROOT
|----routes
|    |- index.js
|    |- detail.js
|    |- users.js
|----public
|    |- css
|    |- fonts
|    |- js
|----views
|    |- error.ejs
|    |- index.ejs
|    |- layout.ejs
|----app.js
|----node_modules
|----package.json

FYI, I have installed NodeJs for Visual Studio extension for my development and I can run it location by clicking the "Run" button within VS. Can anyone kind enough to help? Thanks in advance.

TJ.
  • 241
  • 2
  • 14
  • This looks more like a problem with your template. I don't think you can refer to like that in your layout.ejs file? – Tom Hallam Mar 09 '15 at 14:00
  • @freshnode I'm not sure about this. Never host it on an IIS application before. Maybe this syntax "<%= title %>" it's a asp.net web form syntax and it cannot be resolved? – TJ. Mar 09 '15 at 14:34

2 Answers2

0

I have fixed this issue by using other template engine atpl.js and not ejs.js.

TJ.
  • 241
  • 2
  • 14
0

Webconfig is correct.

Change application pool identity to LocalService, this works for us