错误:运行“ http”时找不到模块“ moduleIntro.js”

编程入门 行业动态 更新时间:2024-10-08 04:28:03

错误:运行“ http”时<a href=https://www.elefans.com/category/jswz/34/1771416.html style=找不到模块“ moduleIntro.js”"/>

错误:运行“ http”时找不到模块“ moduleIntro.js”

我在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并再次运行,即可解决问题。 。

更多推荐

错误:运行“ http”时找不到模块“ moduleIntro.js”

本文发布于:2024-05-07 12:47:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1756304.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:找不到   模块   错误   js   http

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!