pm2 start ngrok http 5000
This is the command I've entered.
But it didn't work out as I wanted.
Please help me to use ngrok using PM2.
If you use ngrk http 5000, you will be able to use it until the terminal is closed.
It works normally.
I want to use this in PM2.
My operating system is Window10 Node-Js.
Thank you.
download / extract to same folder
https://ngrok.com/download
then run following
pm2 start pm2-ngrok.yaml
pm2-ngrok.yaml
apps:
- name : 'ngrok'
script: './ngrok'
args: 'http --hostname=YOURSUBDOMAINHERE.ngrok.io PORTHERE'
instances: '1'
autorestart: true
max_restarts: 10
max_memory_restart: '500M'
watch : false
error_file: 'err-prod.log'
out_file: 'out-prod.log'
log_file: 'combined-prod.log'
run
pm2 startup
pm2 save
to persist across reboots
I think you need to use -- to pass arguments to ngrok when you run it with pm2:
pm2 start ngrok -- http 5000
Related question: How to pass arguments to app using pm2?
So, first install Ngrok with NPM npm install ngrok -g
https://www.npmjs.com/package/ngrok
Then configure your Ngrok.yml acordingly.
After that, you can run your pm2 like in this example.
pm2 start npm --name app -- run develop
pm2 start npm --name ngrok -- run ngrok --all
pm2 monit
So pm2 start npm --name ngrok -- run ngrok --all runes, the yml configuration for all.
Related
i have setup the node project on the AWS EC# instance.
npm start
is working. then project running on the 3000 port. but it will closing when close the terminal. then i have tried PM2.but when run using PM2 its not working. but status showing as online.
these are the command used to run PM2,
npm install pm2 -g
pm2 start app.js
pm2 startup
pm2 save
why is that ? how can i run it?
have you tried pm2 logs?
Also, you can set the project for default like whenever you want to run your server you can simply run by using the pm2 logs command, to set up your server here is the command
Go to your source folder or where your app.js file is stored, and then run this command
pm2 start npm --name "Your Project Name" -- run start
After setting up by this, you can always run your server with pm2 logs command
Thanks
I deployed my Nest.js application on my VPS (Ubuntu 20.04 DO) using pm2 as process manager. Here is my step by step when I'm updating the app.
$ pm2 stop 1
$ kill -9 $(sudo lsof -t -i:4040)
$ npm run build
$ pm2 start 1
Notice that I must kill the port that the app use before I proceed to the build one, how to simplify it and become like these :
$ npm run build
$ pm2 reload 1
So I can deploy my Nest.js app gracefully and achieve at least only 1% downtime
Stop command keeps the app in the apps list while the delete command not.
I think you want something like
start.sh
#!/bin/bash
source .env
ENVIRONMENT="$NODE_ENV"
npm run build || exit
pm2 delete "$ENVIRONMENT"
pm2 start "npm run start:prod" --name "$ENVIRONMENT" --log-date-format 'DD-MM HH:mm:ss.SSS'
If you are not using different environments, an equivalent script would be
#!/bin/bash
npm run build || exit
pm2 delete my_application
pm2 start "npm run start:prod" --name my_application --log-date-format 'DD-MM HH:mm:ss.SSS'
Emitting the --log-date-format is perfectly fine. However, I have included it because I suspect it might become helpful when finding bugs in production down the line.
Right now I am using pm2 to run a node server app. I do that with pm2 start npm. This seems to be independent of the current directory.
I found some mentions online to use pm2 start npm --name "app_name" -- start. However, no matter what name I specify and directory I am inside, it always starts the same app.
Due to the nature of node, I don't run a single .js file and just type npm start in the current directory.
Edit: From my understanding, the problem seems to be that pm2 always starts /usr/bin/npm (Starting /usr/bin/npm in fork_mode (1 instance). So the --name flag doesn't matter much, ie. I can get a list of the same app with different names, and this app is node app A and sometimes node app B. I am kinda lost
What is happening is you have a PM2 app named npm, thus the confusion. You can list pm2 apps with pm2 ls
First, remove it using :
pm2 del npm
Then, start a new app, naming it :
pm2 start npm --name "app_name" -- start
Then, the second app (in the other directory) with :
pm2 start npm --name "app_name2" -- start
You can run Multiple apps using PM2 just follow below steps:
Firstly enter into directory A and start it on PM2 pm2 start server.js --name app-name
Save this in PM2 using pm2 save
Now to run other app you need enter into directory B and start app using
pm2 start server.js --name app-name
Save this process as well, and now check PM2 list using pm2 ls
I've been trying to run pm2 on AWS Elastic Beanstalk's node web service environment but without luck. I start up the express api via: ./node_modules/.bin/pm2 start server.js -i 0 but the server never comes out of a Degraded state. I can run this same command locally just fine. I have ssh'd into the aws instance and looked in the logs, but I don't see any errors. It would be a big help if I could chat with someone that has successfully run pm2 on eb via cluster mode.
Thanks!
I have successfully deploy pm2 on aws elastic beanstalk, it has more than one way to achieve.
You may either add an installation command to the .elasticbeanstalk/config.yml file for pm2 global installation or simply install pm2 into your app and follow the instruction of the link below (recommended way).
https://gist.github.com/Unitech/4c8ea564aa8bf0a389c5
As for the first method, in your config.yml file, simply add the following line(the link above doesn't require this) :
container_commands:
0_install_pm2:
command: "npm install pm2 -g"
You need to manually handcode the start command for your app with this method.
My question is about running HTTP-server in combination with PM2.
The problem I face is that:
HTTP-server requires as input a folder which is the root of the website and a port number to run the website on.
PM2 doesn't recognize the HTTP-server command, even when HTTP-server is installed with the -g option.
So I tried the following (note the double dash which should pass the parameters to the HTTP-server script:
/node_modules/http-server/lib$ pm2 start http-server.js -- /home/unixuser/websiteroot -p8686
But it doesn't work.
I also tried:
http-server /home/unixuser/websiteroot -p8686
Which does work, but doesn't have the great support of pm2 ?
Any suggestions would be great, thanks!
You almost had it.
Check where http-server is located by executing:
$ which http-server
You should get something like this /usr/bin/http-server
Then cd to the directory you want to serve files from and execute:
$ pm2 start /usr/bin/http-server --name my-file-server -- -p 8080 -d false
--name my-file-server is optional, but -- is required to pass arguments through to the http-server command.
pm2 start <location>/http-server --name http-server -- -p <port> -d false
or
PM2 modules it self has in-build static file to be served, which is similar to http-server
https://pm2.keymetrics.io/docs/usage/expose/
pm2 serve <path> <port>
pm2 start 'http-server-spa websiteroot index.html 8080'
if we have a build generated by grunt,then go to its path and hit:
~/app/build/prod$ sudo pm2 start /usr/local/bin/http-server -p 8080
Now check app status at localhost:8080