|
| 1 | +--- |
| 2 | +head: |
| 3 | + - - meta |
| 4 | + - property: 'og:image' |
| 5 | + content: https://docs.sailscasts.com/boring-stack-social.png |
| 6 | +title: Deploy on Railway |
| 7 | +titleTemplate: The Boring JavaScript Stack 🥱 |
| 8 | +description: Deploy your app on Railway |
| 9 | +prev: |
| 10 | + text: 'Render' |
| 11 | + link: '/boring-stack/render' |
| 12 | +next: |
| 13 | + text: Type checking JS files |
| 14 | + link: '/boring-stack/render' |
| 15 | +editLink: true |
| 16 | +--- |
| 17 | + |
| 18 | +# Deploy on Railway |
| 19 | + |
| 20 | +Let's deploy your app on [Railway](https://railway.com) :rocket: |
| 21 | + |
| 22 | +You have two options to deploy your app on Railway... |
| 23 | + |
| 24 | +- Use the **[One-click deploy](#one-click-deploy-with-railway-templates)** if you're just starting out. |
| 25 | +- Or follow the **[GitHub Repo](#github-repo)** steps if you’ve already started building your app. |
| 26 | + |
| 27 | +## One-click deploy mellow-vue |
| 28 | + |
| 29 | +Simply click the button, and Railway will set up everything you need to get your new app live using the `mellow-vue` Railway template. |
| 30 | + |
| 31 | +[](https://railway.com/template/mellow-vue?referralCode=orSqKL) |
| 32 | + |
| 33 | +This template includes: |
| 34 | + |
| 35 | +- **Mellow Vue**: The Boring Stack Mellow template with Vue.js. |
| 36 | +- **PostgreSQL**: A pre-configured PostgreSQL database. |
| 37 | +- **Redis**: A pre-configured Redis instance. |
| 38 | + |
| 39 | +## One-click deploy mellow-react |
| 40 | + |
| 41 | +Simply click the button, and Railway will set up everything you need to get your new app live using the `mellow-react` Railway template. |
| 42 | + |
| 43 | +[](https://railway.com/template/Yqisvu?referralCode=orSqKL) |
| 44 | + |
| 45 | +This template includes: |
| 46 | + |
| 47 | +- **Mellow React**: The Boring Stack Mellow template with React.js. |
| 48 | +- **PostgreSQL**: A pre-configured PostgreSQL database. |
| 49 | +- **Redis**: A pre-configured Redis instance. |
| 50 | + |
| 51 | +## One-click deploy mellow-svelte |
| 52 | + |
| 53 | +Simply click the button, and Railway will set up everything you need to get your new app live using the `mellow-svelte` Railway template. |
| 54 | + |
| 55 | +[](https://railway.com/template/K-dheh?referralCode=orSqKL) |
| 56 | + |
| 57 | +This template includes: |
| 58 | + |
| 59 | +- **Mellow Svelte**: The Boring Stack Mellow template with Svelte.js. |
| 60 | +- **PostgreSQL**: A pre-configured PostgreSQL database. |
| 61 | +- **Redis**: A pre-configured Redis instance. |
| 62 | + |
| 63 | +## GitHub Repo |
| 64 | + |
| 65 | +Push your app to a repo on GitHub. |
| 66 | + |
| 67 | +## Create database |
| 68 | + |
| 69 | +Create the database you want to use for production on Railway and take note of the connection url. |
| 70 | +::: info Database creation guides |
| 71 | +See guides for [MySQL](https://docs.railway.com/guides/mysql), [PostgreSQL](https://docs.railway.com/guides/postgresql), and, [MongoDB](https://docs.railway.com/guides/mongodb) on the Railway docs. |
| 72 | +::: |
| 73 | + |
| 74 | +## Create Redis instance |
| 75 | + |
| 76 | +Create the production Redis instance and take note of the connection url. |
| 77 | +::: info Redis instance guide |
| 78 | +See the [guide to create a Redis instance](https://docs.railway.com/guides/redis) on the Railway docs. |
| 79 | +::: |
| 80 | + |
| 81 | +## Set up database |
| 82 | + |
| 83 | +Depending on the database you want to use for production, [set up that adapter](/boring-stack/database) in `config/environment/production.js` |
| 84 | +::: code-group |
| 85 | + |
| 86 | +```js [PostgreSQL] |
| 87 | +module.exports = { |
| 88 | + datastores: { |
| 89 | + default: { |
| 90 | + adapter: 'sails-postgresql', |
| 91 | + url: process.env.DATABASE_URL |
| 92 | + } |
| 93 | + } |
| 94 | +} |
| 95 | +``` |
| 96 | + |
| 97 | +```js [MySQL] |
| 98 | +module.exports = { |
| 99 | + datastores: { |
| 100 | + default: { |
| 101 | + adapter: 'sails-mysql', |
| 102 | + url: process.env.DATABASE_URL |
| 103 | + } |
| 104 | + } |
| 105 | +} |
| 106 | +``` |
| 107 | + |
| 108 | +```js [MongoDB] |
| 109 | +module.exports = { |
| 110 | + datastores: { |
| 111 | + default: { |
| 112 | + adapter: 'sails-mongo', |
| 113 | + url: process.env.DATABASE_URL |
| 114 | + } |
| 115 | + } |
| 116 | +} |
| 117 | +``` |
| 118 | + |
| 119 | +::: |
| 120 | + |
| 121 | +::: warning |
| 122 | +Don't forget to install the adapter if you haven't already. See the [database](/boring-stack/database) docs for more info. |
| 123 | +::: |
| 124 | + |
| 125 | +## Set up Redis |
| 126 | + |
| 127 | +::: info |
| 128 | +[Create a new Redis instance](https://docs.railway.com/guides/redis) on Railway by following the Railway docs. |
| 129 | +::: |
| 130 | +Set up the Redis adapter in `config/environment/production.js` |
| 131 | + |
| 132 | +```js |
| 133 | +module.exports = { |
| 134 | + session: { |
| 135 | + secret: process.env.REDIS_SECRET |
| 136 | + adapter: '@sailshq/connect-redis', |
| 137 | + url: process.env.REDIS_URL |
| 138 | + } |
| 139 | +} |
| 140 | +``` |
| 141 | + |
| 142 | +## Create a web service |
| 143 | + |
| 144 | +Create a new [Web Service](https://docs.railway.com/quick-start) on Railway, and give Railway permission to access the repo of your app. |
| 145 | + |
| 146 | +If necessary, use the following values during creation: |
| 147 | + |
| 148 | +- **Runtime**: `Node` |
| 149 | +- **Build command**: `npm i` |
| 150 | +- **Start command**: `npm start` |
| 151 | + |
| 152 | +However, Railway is capable of configuring things automatically for you. |
| 153 | + |
| 154 | +## Set environment variables |
| 155 | + |
| 156 | +Add the following evironment variables to your web service: |
| 157 | + |
| 158 | +- `DATABASE_URL`: This should point to the connection string of the database you created. |
| 159 | +- `REDIS_URL`: This should point to the connection string to the Redis instance you created. |
| 160 | +- `SESSION_SECRET`: A unique production session secret to override the one in `config/session.js`. |
| 161 | + |
| 162 | +That’s it! Your app will be live on your Railway URL as soon as the build finishes :tada: |
| 163 | + |
| 164 | +## Celebrate with a :star: |
| 165 | + |
| 166 | +::: tip Star The Boring JavaScript Stack repo on GitHub :star: |
| 167 | +Let's celebrate deploying your app on Railway by giving **The Boring JavaScript Stack** [a star on GitHub](https://github.com/sailscastshq/boring-stack). |
| 168 | +::: |
0 commit comments