我正在尝试让 nowjs 与 express 3.0 一起使用,就像在这个问题中一样。我正在关注代码,但我仍然得到“现在未定义”。
我在 Oracle VM 虚拟机中运行 Ubuntu 12.04。
首先,我创建了一个快速应用程序。
$ express myBrilliantNewApp
然后我在新目录中安装 nowjs。
$ sudo npm install now
添加服务器变量并立即使用它。
var server = http.createServer(app).listen(app.get('port'), function() {
console.log('Express server listening on port ' + app.get('port'));
})
var everyone = require('now').initialize(server);
那么我应该可以做到这一点......
everyone.now.writesomething = function() {
console.log('I would really like it if this shows up at the console')
};
...并打电话并检查每个人的所有内容。
now.writesomething();
console.log(everyone);
这没用。我得到:
[ReferenceError: now is not defined]
ReferenceError: now is not defined
at Object.<anonymous> (/home/jan/dev/apps/probeer1/app.js:44:1)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.runMain (module.js:492:10)
at process.startup.processNextTick.process._tickCallback (node.js:244:9)
谁能告诉我我在这里做错了什么?
完整列表 app.js
/**
* Module dependencies.
*/
var express = require('express')
, routes = require('./routes')
, http = require('http')
, path = require('path');
var app = express();
app.configure(function(){
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')));
});
app.configure('development', function(){
app.use(express.errorHandler());
});
app.get('/', routes.index);
var server = http.createServer(app).listen(app.get('port'), function() {
console.log('Express server listening on port ' + app.get('port'));
})
var everyone = require('now').initialize(server);
everyone.now.writesomething = function() {
console.log('I would really like it if this shows up at the console')
};
now.writesomething();
console.log(everyone);