use nodejs API on port 6000

Posted April 3, 2018 6.2k views
Node.jsUbuntu 16.04

i setup a nodejs droplet. installed pm2 and copied the files to a folder with filezilla. also created a firewall to allow traffic on port 6000 and linked it to the droplet. ran the app with pm2 start app.js

note: this is my first time using digitalocean
note: tried doing calls to my ipv4 address aswell as the floating one

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
2 answers

By default node.js will listen only on localhost/ for local requests. If you specify the IP address in your app as it will listen on all IPs. Another option is to enter only the IP it will be used with (if using a floating IP this is the anchor IP, not the public floating IP users will use).

This shows an example that should listen publicly on port 6000 as long as there is not a firewall blocking it.

var http = require('http');

http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Hello World\n');
}).listen(6000, "");
console.log('Server running at');

digital ocean blocking by default port above :6000 , dont know the reason but , if you will run node less then 6000 then only its working fine for web and APK else only working on APK…