简体   繁体   中英

How to find which port NodeJS uses?

I tried with:

netstat -tupln 

and this is the result:

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      -

If you have an access to your code, Simply go to server.js or whatever filename you have used. Port number is mentioned there. You may find something like

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

const server = http.createServer(app);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM