我正在關注this tutorials來試驗Exress 4路由器。節點app.js不適用於express 4?
但是,當我鍵入:節點server.js,我得到了fllowing錯誤:
> events.js:72
> throw er; // Unhandled 'error' event
> ^Error: listen EADDRINUSE
> at errnoException (net.js:901:11)
> at Server._listen2 (net.js:1039:14)
> at listen (net.js:1061:10)
> at Server.listen (net.js:1135:5)
> at Function.app.listen (/Users/tom/Documents/Projects/express4router/node_modules/express/lib/application.js:531:24)
> at Object.<anonymous> (/Users/tom/Documents/Projects/express4router/server.js:22: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)
它看起來像節點app.js在express4不起作用。我如何在express 4中運行這個簡單的腳本?
var express = require('express');
var app = express();
var port = process.env.PORT || 8080;
app.get('/sample', function(req, res) {
res.send('this is a sample!');
});
app.listen(port);
console.log('Magic happens on port ' + port);
你在窗戶上嗎? – 4dgaurav