How can I change the ip and port of pm2 web interface? - node.js

pm2 web interface - $pm2 web - listen on all the ip available on the machine and I would like it to only listen on localhost or ip of my choice.
$pm2 web
Launching web interface on 0.0.0.0:9615
[PM2][WARN] Applications pm2-http-interface not running, starting...
[PM2] App [pm2-http-interface] launched (1 instances)
[PM2] Process launched
pm2 version 2.1.6
node version 4.7.3
Thanks
EDITED:
I have researched about the environment variables and for the ip and port are:
"env_production" : {
"NODE_ENV": "production",
"PM2_API_IPADDR" : "IP here",
"PM2_API_PORT" : "PORT here"
},
I have tried to start the web interface using the ecosystem.json file and I can not get it.
I am going to open another question on this subject.
How to start pm2 http web interface using the ecosystem.json file?

To start the pm2 web interface with a different port and/or different listening address you can run it with the environment variable you found set.
eg. PM2_API_PORT=1234 PM2_API_IPADDR=192.168.1.1 pm2 web

I recommend setting the environment variables in your ecosystem.json file.
So for example, I usually set NODE_ENV to be production / development or PORT to be 8080 and maybe, in your case, HOST to be localhost.
To access them in your node application, use process.env.<ENVIRONMENT VAR HERE>.
So for example in your javascript: var port_num = process.env.NODE_ENV;
Here's the pm2 documentation on how to set the environment variables, under the env property: http://pm2.keymetrics.io/docs/usage/deployment/

Related

Prevent "EADDRINUSE" with pm2?

I am about to switch my node application server from phusion passenger to pm2.
Most of the ports of my apps are set to 3001. With passenger that's never been a problem, but with pm2 ports collide (EADDRINUSE).
Do I have to set a different port for every app to prevent port collisions?
Yes, of course you need to have each application listen on a different and free port. It is your app that listen to port, not PM2.
You can leave the same port in source code, but in this case, start your app like this to change port when starting your app:
// Work for express and some others
PORT=3012 pm2 start -n "My Application" app.js
That's because express add this in your starter script:
var port = normalizePort( process.env.PORT || '3509' );
Notice that other package may use another name env var, like NODE_PORT for example.

How to node js app move to production see on live api data

I tried to sucessfully bulid node js api using crud Operation and working fine in locally.but how to move production to live see the api data.I tried pm2 but also working for local ipaddress.how to solve this problem any solution..
Change the host name in server.js or index.js file from 'localhost' to 0.0.0.0 then you server will expose to the outside of the your network
Change 'localhost' to '0.0.0.0'
If you have any firewalls you must allow your server port to outside network.
If you are using pm2, you can select environment as production while starting the process.
pm2 start config.js --env production
Ref: http://pm2.keymetrics.io/docs/usage/environment/

Node js deployement in Azure server could not be accesses outside using ip

I tried deploying a simple node js service in azure ubuntu using CLI,console logs says the server is up on port 8080(this same service works perfectly in my local machine),but when i tried to access the public ip from outside,it gives site can't be reached
Following was the output when i deployed my service
azureuser#myVM:~/drugdemo/user_service/drulistService$ vi server.js
azureuser#myVM:~/drugdemo/user_service/drulistService$ node server.js
App is listening on 8080
^C^C
azureuser#myVM:~/drugdemo/user_service/drulistService$ pm2 start server.js
[PM2] Starting
/home/azureuser/drugdemo/user_service/drulistService/server.js in fork_mode (1 instance)
[PM2] Done.
Use `pm2 show <id|name>` to get more details about an app
azureuser#myVM:~/drugdemo/user_service/drulistService$
Please help me with your suggections.
(I already tried changing 'localhost' to '0.0.0.0' and '127.0.0.1' but didn't work for me)
Thank you in advance
Make sure to open the firewall port via Azure as well and not just the server.
This may help: https://blogs.msdn.microsoft.com/pkirchner/2016/02/02/allow-incoming-web-traffic-to-web-server-in-azure-vm/

App not starting with pm2 after stopping execution

I have an app set to listen to port 66.
First I tried to run it with sudo node myapp.js . I was able to access it at the correct url (ip:66). Then I stopped the app (Ctrl+c) and started it with pm2, sudo pm2 start app.js. The status is online. However, that same url is now inaccessible.
Running sudo pm2 logs while the app is started with pm2 gives me the error EACCESS for port 66. No one else is running the app, and I am sure I am only using one console and killing the node service before starting it with pm2.
Pm2 was installed globally. Server is Debian stretch. Nodejs version is 8.x
I am logging as a normal user and using sudo to run the app.
on linux systems normal users are not allowed to listen to ports below 1024. There are several ways around this.
You can change this rule to allow non root users to open such ports. But this is a security risc and is not recommended. So i won't add a link to this solution.
you can also listen to a port that is greater than 1024 and then use a forward rule in your firewall to route port 66 to the port you opened.
https://www.systutorials.com/816/port-forwarding-using-iptables/
my (and pm2's) prefered solution is to listen to a port greater than 1024 and use a reverse proxy like nginx to route apps running on that server.
http://pm2.keymetrics.io/docs/tutorials/pm2-nginx-production-setup

How to access stronglooop loopback application which is running on a subfolder on live server

I have installed strongloop loopback application on a live server on domain e.g: www.abc.com . I have created stronglooop loopback project in a subfolder called "lb" After successfull creation I executed the command "slc run" the terminal logs that your loopback app is running on http://localhost:3000 but when I opened www.abc.com/lb or www.abc.com:3000/lb... it was not running there ... What mistake I did? thanks in advance.
Your loopback running on same domain but on another port so you can access it by http://www.example.com:3000
It's doesn't matter which folder your application is stored. When you run it, by default it runs on default domain on port 3000.
You should be able to deploy your app to that server using the command:
$ slc deploy http://user:pass#prod1.example.com:3000
This is also documented here

Resources