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






你可能感興趣的文章

[JS] 關於Event Loop的一些名詞

[JS] 關於Event Loop的一些名詞

【JS上課筆記】非同步(asynchronous)VS. 同步(synchronous)

【JS上課筆記】非同步(asynchronous)VS. 同步(synchronous)

Filecoin Spec 中文 -- 1

Filecoin Spec 中文 -- 1






留言討論