Deploy PERN stack with Netlify, Railway/Heroku/Render


It’s better to deploy the backend and database in the same service
I tried to deploy both in Heroku/Railway/Render and encountered some problems, record here as a reference

*** Note: I don't use railway so I removed my project temporarily.

The common mistakes

Front end deployed in Netlify

Error: "non-zero exit code: 2"

Solution:

  1. Go to Netlify → site settings → build & deploy

    a. Continuous Deployment → Build Settings → edit settings → Build command: CI= npm run build

    b. Environment → edit variables → Key CI → value false

  2. Go to projects → deploys → trigger deploy

Ref: [SOLVED]-NETLIFY DEPLOYMENT: FAILED DURING STAGE 'BUILDING SITE': BUILD SCRIPT RETURNED NON-ZERO EXIT CODE: 2-REACTJS

Back end deployed in Render

  1. Use res.json() instead of res.send()

  2. Add "homepage": "https://github.com/yourusername/your-repo-name", in the package.json file

  3. Add environment variables

    • DATABASE_URL

    • PORT

    ⭐️ Put environment variable in Heroku/railway/render, there's no need to put them in the .env file

Reference:

  1. How to see an error message from fetch in the front end:

Ref: How to Fix SyntaxError: Unexpected token < in JSON at position 0

  1. Heroku -- Connecting in Node.js






你可能感興趣的文章

一起來讀論文 - Robot Learning via Human Adversarial Games

一起來讀論文 - Robot Learning via Human Adversarial Games

淺談 JavaScript 頭號難題 this:絕對不完整,但保證好懂

淺談 JavaScript 頭號難題 this:絕對不完整,但保證好懂

v-bind 動態屬性指令

v-bind 動態屬性指令






留言討論