Search code examples
node.jsubuntuforever

Running several scripts with forever


I have several scripts in a directory, each of the scripts called bot and it's number, from 1 to the number of the scripts.

What I would like to do is somehow run all of the scripts by 1 command line through the terminal (Using Ubuntu), I've used forever command to run the script without stopping and etc.

Could you make it through the terminal or using a node js script?

Is there any other commands like forever that would do it for me?


Solution

  • You could use it through the command line with the command forever.

    You'll need to create a JSON file with the files you need.

    Example:

    [
      {
        // App1
        "uid": "app1", // ID of the script.
        "append": true,
        "watch": true,
        "script": "bot1.js", // Name of the script
        "sourceDir": "" // Where the script is located. If it's in the
                        // same location as the json file, leave it ""
      },
      {
        // App2 = > Same as app1, just different script name.
        "uid": "app2",
        "append": true,
        "watch": true,
        "script": "bot2.js",
        "sourceDir": ""
      }
    ]
    

    Then you need just to run the JSON file through the forever command. Example:

    forever start apps.json
    

    You can see more information about forever here.