I am currently starting multiple Node.js processes using pm2
. These processes are defined in a JSON file, which is used by running
pm2 start pm2.json
As you can see from the JSON file below, there is a lot of repetition. For example, making a change to the error_file
location or setting the variable time
to true
involves a lot of repetition, which can be tedious with 10-20 such scripts defined in the JSON file.
Is it possible to simplfy the JSON file by setting time
variable only once in the file and have it apply to all processes?
Also, is it possible to use a template to define error_file
and out_file
, such as "../logs/${name}-error.log"
?
Example pm2.json
{
"apps": [
{
"name": "foo-a",
"script": "./foo/a.js",
"args": "-e apple",
"error_file": "../logs/foo-a-error.log",
"out_file": "../logs/foo-a-out.log",
"time": true
},
{
"name": "foo-b",
"script": "./foo/b.js",
"args": "-e banana",
"error_file": "../logs/foo-b-error.log",
"out_file": "../logs/foo-b-out.log",
"time": true
}, {
"name": "bar-c",
"script": "./bar/c.js",
"args": "-e cranberry",
"error_file": "../logs/bar-c-error.log",
"out_file": "../logs/bar-c-out.log",
"time": true
},
...
You can use js
file instead json
file, it will allow you to create and use common variable/function for repetition part
.
const time = true
module.exports = {
"apps": [
{
"name": "foo-a",
"script": "./foo/a.js",
"args": "-e apple",
"error_file": "../logs/foo-a-error.log",
"out_file": "../logs/foo-a-out.log",
"time": time
},
{
"name": "foo-b",
"script": "./foo/b.js",
"args": "-e banana",
"error_file": "../logs/foo-a-error.log",
"out_file": "../logs/foo-a-out.log",
"time": time
}, {
"name": "bar-c",
"script": "./bar/c.js",
"args": "-e cranberry",
"error_file": "../logs/bar-c-error.log",
"out_file": "../logs/bar-c-out.log",
"time": time
},
...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.