我試圖讓nowjs使用快遞3.0,就像在this問題一樣。我正在關注代碼,但我仍然得到「現在沒有定義」。Nowjs仍然沒有使用快遞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);
日Thnx與我忘了代碼修修補補後再試一次,是我不好。放回去。然而,相同(種類)的問題 – 2012-08-14 05:28:10
您是否在客戶端包含了now.js腳本引用?查看更新的答案。 – JohnnyHK 2012-08-14 15:20:31
我試圖做一個乾淨的錯誤再現,從服務器端調用一個函數。查看更新的問題。這應該工作嗎? – 2012-08-14 21:41:44