0

I've created a build environment using express JS. But, I got into trouble to configure AngularJS view -- Pleas help me to fix this issue..

1:

var express = require('express');
var http = require('http');
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 app = express();
var httpServer = http.createServer(app);
// view engine setup
//app.set('views', path.join(__dirname, 'views'));
//app.set('view engine', 'jade');
//res.render('dist/index.html');
//app.engine('html', require('ejs').renderFile);


//Trying to setup my view over here -- dist folder is holding the index.html file 

app.set('views', __dirname + '/dist');
app.set('view engine', 'html');


// uncomment after placing your favicon in /public
//app.use(favicon(__dirname + '/dist/favicon.ico'));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static('./dist'));

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

// 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: {}
  });
});

httpServer.listen('8080');
console.log("server is started");

Above build setup was throwing following error ::

Error : Can't find module 'html' -- I'm not sure how to configure Node.Js to refer the angular JS veiw and all the injuctors..

Viktor S.
  • 12,736
  • 1
  • 27
  • 52
  • Ok, what your application should do? Serve static content, right? (such as html/css/js files) Is that the only goal for now? – zaynetro May 21 '15 at 05:15

1 Answers1

0

The problem is with this line:

app.set('view engine', 'html');

You are trying to specify view engine with html value, which is not a view engine (expressjs tries to require html module internaly, but doesn't find it). If you need to serve just html files without templating use:

app.use(express.static(__dirname + '/public'));

And move all files you want to serve to public folder.

UPD: you can actually require html file from jade

in views/index.jade

include plain.html

in views/plain.html

<!DOCTYPE html>
...

and app.js can still just render jade:

res.render(index)

Andrew Homeyer's answer

References:

zaynetro
  • 2,298
  • 20
  • 28
  • Thank you very much for your help.. But, I'm still not able to do a setup.. I'm still missing something.. Please advise me.. – George Ananth May 21 '15 at 03:49