title: Setting up app.yaml file for Node.js and React.js deployment to App Engine
body: <p>I'm trying to deploy my project which has a server-side directory and a client-side. I'm also using pm2 to boot up the services for both sides... Here is the <strong>folder structure directory</strong>:</p>
  
  <pre><code>MyProject
  +-- server
  |   --- app.js
  |   --- app.yaml
  |   --- package.json
  +-- client
  |   +-- build
  |       --- index.html
  |   --- package.json
  |....
  --- .gitignore
  </code></pre>
  
  <p><strong>Server script of package.json</strong></p>
  
  <pre><code>{...
  "scripts": {
      "client": "npm start --prefix ../client",
      "deploy": "gcloud app deploy app.yaml",
      "dev": "concurrently \"npm run build\" \"npm run client\"",
      "start": "pm2 start app.config.json"
    },
  ...
  }
  </code></pre>
  
  <p><strong>app.config.json</strong> file because I'm using pm2:</p>
  
  <pre><code>{
      "apps" : [
          {
              "name"      : "clientApp",
              "script": "node",
              "args"    : "../client/scripts/start.js"
          },
          {
              "name"      : "serverApp",
              "script"    : "node",
              "args": "./bin/www"
          }
      ]
    }
  </code></pre>
  
  <p><strong>app.js</strong></p>
  
  <pre><code>app.use(express.static(path.join(__dirname, '../client/build')));
  </code></pre>
  
  <p>This is the setup for the Server. Now here is the <strong>Client side.
  package.json</strong></p>
  
  <pre><code>"scripts": {
      "start": "pm2 start scripts/start.js --name clientApp",
      "build": "node scripts/build.js",
      "serve": "serve -s build -l 8080",
    },
    "proxy": "http://localhost:5000",
  </code></pre>
  
  <p>Most importantly, the <strong>app.yaml</strong>:</p>
  
  <pre><code>runtime: nodejs
  env: flex
  
  handlers:
    - url: /api/.*
      script: auto
    - url: /
      static_files: client/build/index.html
      upload: client/build/index.html
    - url: /
      static_dir: client/build
    - url: /static
      static_dir: client/build/static
    - url: /.*
      secure: always
      redirect_http_response_code: 301
      script: auto
  
  manual_scaling:
    instances: 1
  
  resources:
    cpu: 2
    memory_gb: 8.0
    disk_size_gb: 20
  
  </code></pre>
  
  <p>The error I'm getting is Application startup error! Code: APP_CONTAINER_CRASHED, why is this happening? Did i source the client side directory incorrectly in the app.yaml???</p>
  
  <pre><code>ERROR: (gcloud.app.deploy) Error Response: [9] 
  Application startup error! Code: APP_CONTAINER_CRASHED
  yarn run v1.17.3
  $ pm2 start app.config.json
  ...
  ...
  ...
  [PM2] Spawning PM2 daemon with pm2_home=/root/.pm2
  [PM2] PM2 Successfully daemonized
  [PM2][WARN] Applications clientApp, serverApp not running, starting...
  [PM2] App [clientApp] launched (1 instances)
  [PM2] App [serverApp] launched (1 instances)
  ┌─────┬──────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
  │ id  │ name         │ namespace   │ version │ mode    │ pid      │ uptime │ \u21ba    │ status    │ cpu      │ mem      │ user     │ watching │
  ├─────┼──────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
  │ 0   │ clientApp    │ default     │ N/A     │ fork    │ 50       │ 0s     │ 0    │ online    │ 0%       │ 28.2mb   │ root     │ disabled │
  │ 1   │ serverApp    │ default     │ N/A     │ fork    │ 56       │ 0s     │ 0    │ online    │ 0%       │ 25.4mb   │ root     │ disabled │
  └─────┴──────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
  Done in 2.05s.
  
  error Command failed with exit code 1.
  </code></pre>