68

I have an electron app which uses pm2 to start some apps using the pm2 module.Everything is fine.However I am trying to implement the following feature:Renaming an app you have started.I know that using the cli I can do the following:

pm2 restart app --name"New name";

So I found the pm2.restart function which takes an Object and a callback as a parameter.So I tried this:

var options = {app:"Blogsport App",name:"New name"};
var callback = function(err){
   if(err) {console.log('Failed')}
   else {console.log('App renamed')}
};

pm2.restart(options,callback);

This will always log "App renamed".However If I do pm2 list I see that the app has not be renamed.Is there anything I can do to rename an app without deleting it and start it again with a different name?

Manos Kounelakis
  • 2,848
  • 5
  • 31
  • 55
  • try adding the `--update-env` param in options – Pogrindis Jun 07 '18 at 08:23
  • How can I do this? – Manos Kounelakis Jun 07 '18 at 08:24
  • just for a test you could write something like `exec('pm2 restart app --name "New name"', function(err, stdout, stderr){ if(err) console.log(err);}` etc.. See if it's working that way, if so then it might be a bug ? you will need child_proc `var exec = require('child_process').exec;` – Pogrindis Jun 07 '18 at 08:27
  • I will be able to test in an hour or so – Pogrindis Jun 07 '18 at 08:27
  • I know I can do this with exec by replacing app with my app name but I would prefer to do this using the pm2 if that's possible – Manos Kounelakis Jun 07 '18 at 08:28
  • So just looking at restart can you try : `pm2.restart(options,{rawArgs : ["--update-env"] },callback);` ? or add the `rawArgs` attribut in the `options` variable.. As I say I will be able to test in 1 hour : https://github.com/Unitech/pm2/blob/master/lib/API.js#L1434 – Pogrindis Jun 07 '18 at 08:35
  • OK .I tried both methods but to no avail. – Manos Kounelakis Jun 07 '18 at 08:55

3 Answers3

198

you can try this:

pm2 restart id --name newName

Example: your id is 1 , then you can type : pm2 restart 1 --name development

Deepak Mahakale
  • 22,834
  • 10
  • 68
  • 88
gentur ariyadi
  • 2,105
  • 1
  • 10
  • 10
  • If you've previously dumped your processes I would suggest running `pm2 save` afterwards to synchronize your changes with saved process list. – luissquall Aug 23 '22 at 14:27
18

you can do


pm2 delete id|name  
pm2 start app.js -n newname

or

pm2 restart id|name -n newname
Faisal Ahmed
  • 350
  • 3
  • 7
1
pm2 ls

to see your app id

then you have two options delete and start again

pm2 delete <id> 
pm2 start index.js --name newname

or just restart to keep same id

pm2 restart <id> --name newname
Ahmed Elsayed
  • 338
  • 2
  • 11