{"record":{"id":"37b7c556dae94cc5","repo":"Unitech/pm2","slug":"you-cannot-set-a-pm2-home-and-independent-instance","errorCode":null,"errorMessage":"You cannot set a pm2_home and independent instance in same time","messagePattern":"You cannot set a pm2_home and independent instance in same time","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/API.js","lineNumber":78,"sourceCode":"    this.daemon_mode = typeof(opts.daemon_mode) == 'undefined' ? true : opts.daemon_mode;\n    this.pm2_home = conf.PM2_ROOT_PATH;\n    this.public_key = conf.PUBLIC_KEY || opts.public_key || null;\n    this.secret_key = conf.SECRET_KEY || opts.secret_key || null;\n    this.machine_name = conf.MACHINE_NAME || opts.machine_name || null\n\n    /**\n     * CWD resolution\n     */\n    this.cwd = process.cwd();\n    if (opts.cwd) {\n      this.cwd = path.resolve(opts.cwd);\n    }\n\n    /**\n     * PM2 HOME resolution\n     */\n    if (opts.pm2_home && opts.independent == true)\n      throw new Error('You cannot set a pm2_home and independent instance in same time');\n\n    if (opts.pm2_home) {\n      // Override default conf file\n      this.pm2_home = opts.pm2_home;\n      conf = Object.assign(conf, path_structure(this.pm2_home));\n    }\n    else if (opts.independent == true && conf.IS_WINDOWS === false) {\n      // Create an unique pm2 instance\n      const crypto = require('crypto');\n      var random_file = crypto.randomBytes(8).toString('hex');\n      this.pm2_home = path.join('/tmp', random_file);\n\n      // If we dont explicitly tell to have a daemon\n      // It will go as in proc\n      if (typeof(opts.daemon_mode) == 'undefined')\n        this.daemon_mode = false;\n      conf = Object.assign(conf, path_structure(this.pm2_home));\n    }","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/Unitech/pm2/blob/31adee8048dbbc1ee36a7df7cdbcaca2559708df/lib/API.js#L60-L96","documentation":"Thrown in the PM2 API constructor. The options object lets you control where PM2 stores its state (PM2_HOME): either pin it to an explicit path via pm2_home, or ask PM2 to mint a fresh unique home under /tmp via independent:true. These two are mutually exclusive — you cannot both name the home and ask for a random one in the same call.","triggerScenarios":"Instantiating `new PM2({ pm2_home: '/some/path', independent: true })` (or pm2.connect with the same opts) — both keys present at once.","commonSituations":"Merging two config presets where one sets pm2_home and another sets independent:true; copy-pasting options from different examples; test harnesses that force independent mode combined with a fixed home.","solutions":["Remove one of the two keys — choose a single PM2 home strategy.","If you want a dedicated isolated instance with a random home, drop pm2_home and keep independent:true.","If you want a fixed, known location, drop independent and keep pm2_home."],"exampleFix":"// before\nnew PM2({ pm2_home: '/var/pm2', independent: true });\n// after\nnew PM2({ pm2_home: '/var/pm2' });","handlingStrategy":"validation","validationCode":"function createPm2(opts) {\n  if (opts && opts.pm2_home && opts.independent === true) {\n    throw new TypeError('pm2_home and independent are mutually exclusive; pass exactly one');\n  }\n  return new (require('pm2'))(opts);\n}","typeGuard":"function isValidPm2Opts(opts) {\n  return !(opts && opts.pm2_home && opts.independent === true);\n}","tryCatchPattern":null,"preventionTips":["Treat independent:true as an alternative to pm2_home, never an addition.","Never merge unrelated config presets without deduping mutually-exclusive keys.","Assert the invariant in your own factory wrapping new PM2(opts)."],"tags":["configuration","pm2-home","constructor"],"backgroundTag":null,"analyzedSha":"31adee8048dbbc1ee36a7df7cdbcaca2559708df","analyzedAt":"2026-08-13T03:49:51.765Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}