zoukankan      html  css  js  c++  java
  • nodejs报错 events.js:72 throw er; // Unhandled 'error' event

    var http = require('http');

    var handlerRequest = function(req,res){
    res.end('hello');
    };

    var webServer = http.createServer(handlerRequest);
    webServer.listen(9090);

    console.log('webServer running on 9090..');

    以上代码在windows上运行没有错误,然后我把代码上传到centos虚拟机里,运行后报错

    events.js:72
    throw er; // Unhandled 'error' event
    ^
    Error: listen EADDRINUSE
    at errnoException (net.js:905:11)
    at Server._listen2 (net.js:1043:14)
    at listen (net.js:1065:10)
    at Server.listen (net.js:1139:5)
    at Object.<anonymous> (/home/test/port8/web.js:8:11)
    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)

    意思似乎是我没有对错误进行处理,下面说是地址被占用

    然后在linux上执行如下语句

    [root@nodejs port8]# netstat -lntp | grep 9090
    tcp 0 0 0.0.0.0:9090 0.0.0.0:* LISTEN 24909/node

    发现这个9090端口其实已经被占用了。

    所以:如果你随意写http.listen()的端口,一定要先判断一下端口是否已经被占用。

  • 相关阅读:
    ESP8266 在线构建 固件
    NodeMCU 物联网开发快速上手
    vofaplus-plugins dtantdir
    欧拉角
    DebugView 简单使用
    Intrusion Detection Evaluation Dataset (CIC-IDS2017)
    ureport
    how to ignore server cert error in javamail
    465和587区别
    JavaMail 发送邮件阻塞问题解决——设置 smtp 超时时间
  • 原文地址:https://www.cnblogs.com/wangduanduan/p/5382493.html
Copyright © 2011-2022 走看看