search

Home  >  Q&A  >  body text

How to automatically restart a process using Node in NW.JS?

My project is developed based on NW.JS. When a certain condition is met, I need to restart the client, but I really don’t know enough about NODE. I need help from experts to solve it. Thank you! !
Whether it is the nw.js method or the node method, as long as the program can be restarted~

阿神阿神2778 days ago559

reply all(2)I'll reply

  • 我想大声告诉你

    我想大声告诉你2017-05-16 13:41:20

    var nwRestart = function () {
        var child, child_process = require('child_process');
        if (process.platform == "darwin") {
            child = child_process.spawn("open", ["-n", "-a", process.execPath.match(/^([^rrreee]+?\.app)\//)[1]], { detached: true });
        } else {
            child = child_process.spawn(process.execPath, [], { detached: true });
        }
        child.unref();
        require("nw.gui").Window.get().hide();
        process._nw_app.quit();
    };
    nwRestart();
    

    This is suitable for older nw clients. If the nw version you are using is relatively new, you need to modify it accordingly, mainly to get nw_app to exit at the end

    reply
    0
  • 迷茫

    迷茫2017-05-16 13:41:20

    @QiCheen Thank you so much~Thank you!

    reply
    0
  • Cancelreply