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:
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
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
Use
res.json()
instead ofres.send()
Add
"homepage": "https://github.com/yourusername/your-repo-name",
in the package.json fileAdd environment variables
DATABASE_URL
PORT
⭐️ Put environment variable in Heroku/railway/render, there's no need to put them in the
.env
file
Reference:
- How to see an error message from fetch in the front end:
Ref: How to Fix SyntaxError: Unexpected token < in JSON at position 0