In this post, we'll walk through the steps to deploy a Node.js app on Railway.
What is Node.js?
What is Railway?
Railway is a modern app hosting platform that makes it easy to deploy production-ready apps quickly. Railway offers persistent database services for PostgreSQL, MySQL, MongoDB, and Redis, as well as application services with a GitHub repository as the deployment source. For the latter, Railway can automatically determine the application runtime and deploy the service. Railway offers several one-click starters for popular applications, including Node.js. Since we are just testing the waters, Railway's free tier should be sufficient to host the service.
Deploy a Simple Node.js App on Railway
Sign up for an account with Railway using GitHub, and click
Authorize Railway App when redirected. Review and agree to Railway's Terms of Service and Fair Use Policy if prompted. Launch the Node.js one-click starter template (or click the button below) to deploy a Node.js app instantly on Railway.
You'll be given an opportunity to change the default repository name and set it private, if you'd like. Accept the defaults and click
Deploy; the deployment will kick off immediately.
Once the deployment completes, a simple Node.js app will be available at a default
xxx.up.railway.app domain - launch this URL to access the app. If you are interested in setting up a custom domain, I covered it at length in a previous post - see the final section here.
If you want to modify the app, here's a few things to understand first:
index.jsfile only covers the default
/route, which returns a simple
Hello Worldoutput. To extend this, you'll need something like the Express web application framework - see an example here.
package.jsondefines the project metadata, scripts and dependencies. Update accordingly if you add other packages.
- The app will listen on port
3000by default; update the
PORTenvironment variable to change the default port.
In conclusion, deploying a Node.js app on Railway is a straightforward process, made even easier by the one-click template. Go forth and deploy!