我用一個簡單的節點應用試驗...爲什麼我不能在端口3000上運行這個節點應用程序?
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, "127.0.0.1");
console.log('Server running at http://127.0.0.1:1337/');
我能夠瀏覽到主機:1337 /和我看到的「Hello World」。但是,如果我將端口更改爲3000,則無法加載頁面。
適合我。最好的猜測是你在'console.log'調用中的字符串中進行了更改,但忘記在'listen'調用中更改它,或者其他人正在使用端口3000. –
可能是因爲別的東西正在使用3000。另外,最好有一個像引用端口的單個變量的東西;即使在短代碼片段中,也會在代碼中放置多個相同的常量值。 'var ip ='127.0.0.1',port = 3000'和'listen(ip,port); console.log('運行在http://'+ ip +'的服務器:'+ port)'; – vogomatix
你知道它vogomatix ...好吧,我覺得很笨...我改變控制檯日誌中的端口...不是在監聽方法的參數。 – Lumbee