[英]Error: Cannot find module “moduleIntro.js” when running “http”
我在 Node.Js 中嘗試了一個基本的初學者程序,我想在其中使用內置模塊“http”。 執行 http.createServer() 的基本程序后。 下面是我的源代碼。
var http = require('http');
http.createServer(function (req, res) {
res.write('Hello World!');
res.end();
}).listen(8080);
在 cmd 中運行代碼時,它沒有運行並顯示以下錯誤。
events.js:287
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE: address already in use :::8080
at Server.setupListenHandle [as _listen2] (net.js:1313:16)
at listenInCluster (net.js:1361:12)
at Server.listen (net.js:1449:7)
at Object.<anonymous> (F:\NodeJS\first app\w3schools\moduleIntro,.js:7:4)
at Module._compile (internal/modules/cjs/loader.js:1133:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
at Module.load (internal/modules/cjs/loader.js:977:32)
at Function.Module._load (internal/modules/cjs/loader.js:877:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
at internal/main/run_main_module.js:18:47
Emitted 'error' event on Server instance at:
at emitErrorNT (net.js:1340:8)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
code: 'EADDRINUSE',
errno: 'EADDRINUSE',
syscall: 'listen',
address: '::',
port: 8080
}
好的,您的代碼實際上沒有問題 8080 已經在其他任何地方運行,因此您不能一次運行相同的端口號,因此只需關閉所有正在運行的進程,或者您只需關閉 PC 並再次運行,問題就會得到解決。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.