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






你可能感興趣的文章

D55_W7 寫作業,拆任務

D55_W7 寫作業,拆任務

Fetch 與 Promise (一):初探 Fetch

Fetch 與 Promise (一):初探 Fetch

ASP.NET Core Web API 入門教學 - 創建第一支HelloWorld API

ASP.NET Core Web API 入門教學 - 創建第一支HelloWorld API






留言討論