我喜欢用 CoffeeScript 编写我的堆栈,我只是想知道如何让它在运行时使用 Node.js 自动编译,这样我就不必手动编译我编辑的每个咖啡文件并将 .js 移动到文件中,这就是我现在所拥有的(只是为了测试);
/routes/index.coffee:
exports.index = (req, res) ->
res.render "index",
title: "Express"
app.js:
/**
* Module dependencies.
*/
require('coffee-script');
var express = require('express')
, staticp = require('./routes/index')
, user = require('./routes/user')
, http = require('http')
, path = require('path');
var app = express();
// all environments
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
// development only
if ('development' == app.get('env')) {
app.use(express.errorHandler());
}
app.get('/', staticp.index);
app.get('/users', user.list);
http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
Error:
https://gist.github.com/Gacnt/8f550196813df8fe1d5f