2014-07-17 32 views
0

我有以下文件:node.js中不能正常工作時,Windows 7

var express = require('express'), 
    http = require('http'), 
    app = express(), 
    httpServer = http.createServer(app); 

app.configure(function() { 
    app.set('port', 3000); 
    app.use(express.static(__dirname + '/public')); 
}); 

httpServer.listen(app.get('port'), function() { 
    console.log("Express server listening on port %s.", httpServer.address().port); 
}); 

但是這給後續的錯誤:

C:\var\www\stage.mayfieldafc.com>nodemon http.js 
18 Jul 01:19:29 - [nodemon] v1.2.1 
18 Jul 01:19:29 - [nodemon] to restart at any time, enter `rs` 
18 Jul 01:19:29 - [nodemon] watching: *.* 
18 Jul 01:19:29 - [nodemon] starting `node http.js` 

C:\var\www\stage.mayfieldafc.com\http.js:8 
app.configure(function() { 
    ^
TypeError: Object function (req, res, next) { 
    app.handle(req, res, next); 
    } has no method 'configure' 
    at Object.<anonymous> (C:\var\www\stage.mayfieldafc.com\http.js:8:5) 
    at Module._compile (module.js:456:26) 
    at Object.Module._extensions..js (module.js:474:10) 
    at Module.load (module.js:356:32) 
    at Function.Module._load (module.js:312:12) 
    at Function.Module.runMain (module.js:497:10) 
    at startup (node.js:119:16) 
    at node.js:906:3 
18 Jul 01:19:29 - [nodemon] app crashed - waiting for file changes before starting... 

同時安裝nodemonexpress,我可以看到後都裏面的文件夾node_modules

此外,當控制檯記錄express返回我看到它有correc tly加載模塊。

如何驗證我的節點安裝?或者更好的解決它。

回答

1

快遞4不再有app.configure()。請參閱the wiki從Express 3遷移到Express 4.

1

方法app.configure已從express 4中刪除。所以現在你不得不說出類似波紋管的東西。

app.set('port', 3000); 
app.use(express.static(__dirname + '/public')); 

代替

app.configure(function() { 
    app.set('port', 3000); 
    app.use(express.static(__dirname + '/public')); 
}); 

,並有許多其他已進行了更改。