代码之家  ›  专栏  ›  技术社区  ›  Joe

如何找到NodeJS使用的端口?

  •  -1
  • Joe  · 技术社区  · 7 年前

    我试过:

    netstat -tupln 
    

    结果如下:

    Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
    tcp        0      0 127.0.0.1:5000          0.0.0.0:*               LISTEN      -
    tcp        0      0 127.0.0.1:5001          0.0.0.0:*               LISTEN      -
    tcp        0      0 127.0.0.1:53            0.0.0.0:*               LISTEN      -
    tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -
    tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      -
    tcp        0      0 0.0.0.0:4445            0.0.0.0:*               LISTEN      -
    tcp        0      0 127.0.0.1:8126          0.0.0.0:*               LISTEN      -
    
    1 回复  |  直到 7 年前
        1
  •  0
  •   Shahzeb Khan    7 年前

    如果您有权访问代码,只需转到 server.js 或者你用过的任何文件名。这里提到了端口号。你可能会发现

    const port = process.env.APP_PORT || 80;
    app.set('port', port);
    
    const server = http.createServer(app);