rename process using pm2 programmatic api

node.jsElectronPm2

node.js Problem Overview


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?

node.js Solutions


Solution 1 - node.js

you can try this:

pm2 restart id --name newName

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

Solution 2 - node.js

you can do


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

or

pm2 restart id|name -n newname

Solution 3 - node.js

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionManos KounelakisView Question on Stackoverflow
Solution 1 - node.jsgentur ariyadiView Answer on Stackoverflow
Solution 2 - node.jsFaisal AhmedView Answer on Stackoverflow
Solution 3 - node.jsAhmed ElsayedView Answer on Stackoverflow