title: How To Tell pm2 to Use Specific Node Version On Deploy
body: <p>EDIT -- After attempting to just install puppeteer on my machine using an old version of node (8.1.0), it throws the same error. The problem therefore must be that when connecting to the machine, it's not loading in the correct node version. The question then, is <strong>how does one run the pm2 post-deploy hook using the correct node.js version?</strong></p>
  
  <p>I'm getting a very strange error when attempting to deploy my web-scraping application using <code>pm2</code> deploy. The error is coming during the <code>post-install</code> hook of the <code>pm2</code> deployment process, which is when <code>yarn</code> is installing the various packages to my remote machine (Ubuntu 18.04).</p>
  
  <p>The error looks like this:</p>
  
  <pre><code>....The rest of the yarn installation...
  
  [4/4] Building fresh packages...    
  error /home/harrison/gql3.0_processors/source/node_modules/puppeteer: Command failed.
  Exit code: 1
  Command: node install.js
  Arguments:
  Directory: /home/harrison/gql3.0_processors/source/node_modules/puppeteer
  Output:
  /home/harrison/gql3.0_processors/source/node_modules/puppeteer/install.js:175
              } catch {
                      ^
  
  SyntaxError: Unexpected token {
      at createScript (vm.js:80:10)
      at Object.runInThisContext (vm.js:139:10)
      at Module._compile (module.js:616:28)
      at Object.Module._extensions..js (module.js:663:10)
      at Module.load (module.js:565:32)    
      at tryModuleLoad (module.js:505:12)
      at Function.Module._load (module.js:497:3)
      at Function.Module.runMain (module.js:693:10)
      at startup (bootstrap_node.js:188:16)
      at bootstrap_node.js:609:3
  info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
  
    post-deploy hook failed
  
  Deploy failed
  </code></pre>
  
  <p>This is coming from the <code>install.js</code> file within the <code>puppeteer</code> directory of my <code>node_modules</code> folder, which is a dependency that I'm using for my project.</p>
  
  <p>I'm inclined to think that this is due to some sort of error with my node version when I'm installing the application remotely? Can anyone offer some guidance? </p>
  
  <p>My <code>pm2</code> deploy file is as follows (for more info, go here: <a href="https://pm2.keymetrics.io/docs/usage/application-declaration/" rel="nofollow noreferrer">https://pm2.keymetrics.io/docs/usage/application-declaration/</a>)</p>
  
  <pre><code>require("dotenv").config({ path: `./envs/.env.production` });
  const path = require("path");
  
  let hosts = process.env.HOSTS.split(",");
  let hostsBashArgs = process.env.HOSTS.replace(/,/g, " "); // Pass as args to bash script
  
  module.exports = {
    apps: [
      {
        name: process.env.APP_NAME,
        args: ["--color"],
        interpreter: process.env.NODE_PATH, // Installation of node on my remote machine, it's ––&gt; `/home/harrison/.nvm/versions/node/v13.7.0/bin/`
        cwd: path.resolve(process.env.PROJECT_PATH, "current"), // Where post-deploy runs
        script: "dist/index.js", // Webpacked server file
        instances: process.env.INSTANCES || 0,
        exec_mode: "cluster",
        env: {
          ...process.env,
        },
      },
    ],
    deploy: {
      production: {
        user: "harrison",
        host: hosts,
        key: "~/.ssh/id_rsa2",
        ref: "origin/master",
        repo: process.env.GIT_REPO,
        path: process.env.PROJECT_PATH,
        "pre-deploy-local": `./deployEnvs.sh ${process.env.PROJECT_PATH} ${hostsBashArgs}`,
        //// THIS IS THE STEP WHICH FAILS 
        "post-deploy": `yarn install --ignore-engines &amp;&amp; \
         yarn prod:build &amp;&amp; \
         yarn prod:serve`,
      },
    },
  };
  </code></pre>