Simple Node + Express + Postgres Deployment with Railway and Supabase
Requirement:
- Simple git repo that use node + express + sequelize (you can fork this repo if you don’t already have server repos)
- make sure on your package.json you already write your start script
- Postgres Connection String with Supabase (follow this link until step 3 to get your postgres connection, anyways it’s app.supabase.com not app.supabase.io)
Step 1 register railway and login, it’s better to have starter plan verified account
Step 2 Create a new project, in this article i will use simple git repo above to deploy
Step 3 Give railway permission by clicking “Deploy from Github repo”, you can choose your repo to deploy
Step 4 Add environment variables that you used on your server repo, i use NODE_ENV and DATABASE_URL as environment variables. You can insert postgre connection string from app.supabase.com to DATABASE_URL
Step 5 Set your root directory folder, on my repo my server is located at /server folder directory, don’t forget to save the setup
Step 6 Click generate domain so your application can be accessed by HTTPS
Step 7 When we try to hit one of our endpoints it shows us sequelizeDatabaseError. Why ? it’s because we need to migrate our database first
Step 8 Install railway CLI on your local machine https://docs.railway.app/develop/cli (you can use npm too for installation)
Step 9 Type railway login from your local terminal and press enter
Step 10 Type railway status to see linked project to your local environment
Type railway link and choose your project if your current project is not written on railway status log message
Step 11 run migration and seeding from your local machine, make sure you have NODE_ENV=production on your railways variable environments
Step 12 Now you can try again to hit your endpoint ! And your data will be retrieved
That’s it folks ! Thanks for reading !