<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Hannah Liao</title>
    <description>The latest articles on Forem by Hannah Liao (@hannliao).</description>
    <link>https://forem.com/hannliao</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2310332%2Fce5d03b4-d9ae-48b9-ba27-07a70f78aa6b.png</url>
      <title>Forem: Hannah Liao</title>
      <link>https://forem.com/hannliao</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/hannliao"/>
    <language>en</language>
    <item>
      <title>How to deploy PostgreSQL database to Railway</title>
      <dc:creator>Hannah Liao</dc:creator>
      <pubDate>Wed, 30 Oct 2024 22:55:09 +0000</pubDate>
      <link>https://forem.com/hannliao/how-to-deploy-postgresql-database-to-railway-7l4</link>
      <guid>https://forem.com/hannliao/how-to-deploy-postgresql-database-to-railway-7l4</guid>
      <description>&lt;p&gt;You've finished building a Node.js app and pushed it to GitHub, but how do you host it on Railway?&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;In app.js of your project, add '0.0.0.0' to the app.listen function as shown below. Railway requires your app to explicitly listen on all network interfaces (0.0.0.0) instead of just the default localhost. Push this change to GitHub.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjidn4uivl26cuudm4ho7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjidn4uivl26cuudm4ho7.png" alt="Image description" width="800" height="209"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;From the Railway dashboard, select &lt;strong&gt;New&lt;/strong&gt; and &lt;strong&gt;Deploy from GitHub repo&lt;/strong&gt;. Select your project, click &lt;strong&gt;Deploy Now&lt;/strong&gt;, and wait for deployment to complete.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy8vtfzmbkm5k2ict0cc4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy8vtfzmbkm5k2ict0cc4.png" alt="deploy-project" width="637" height="514"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Close the side window and click on the &lt;strong&gt;Create&lt;/strong&gt; button. Select &lt;strong&gt;Database&lt;/strong&gt; and then &lt;strong&gt;Add PostgreSQL&lt;/strong&gt;. Wait for deployment to complete.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7a7wcxd8rwkpnmsk5fcy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7a7wcxd8rwkpnmsk5fcy.png" alt="Image description" width="800" height="557"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;With the project card still selected, navigate to the &lt;strong&gt;Variables&lt;/strong&gt; tab. Click on &lt;strong&gt;New Variable&lt;/strong&gt; and add the Railway-provided &lt;strong&gt;DATABASE_URL&lt;/strong&gt;. You should be able to start typing it in VARIABLE_NAME and select it from the dropdown menu. Railway will populate the value for you, then click &lt;strong&gt;Add&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4dqd5r5dpx7a3edrykid.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4dqd5r5dpx7a3edrykid.png" alt="Image description" width="800" height="333"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Click on the &lt;strong&gt;Postgres&lt;/strong&gt; card on the left and navigate to the &lt;strong&gt;Variables&lt;/strong&gt; tab. You should see all the Railway-provided Postgres variables. Copy the &lt;strong&gt;DATABASE_PUBLIC_URL&lt;/strong&gt; (if you want your app to be public).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8f2cyahcvg722cnfjjyc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8f2cyahcvg722cnfjjyc.png" alt="Image description" width="800" height="401"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In your terminal, change directory to your project. Run the following commands:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export DATABASE_URL=&amp;lt;DATABASE_PUBLIC_URL&amp;gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Run your script to populate the database.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node db/populatedb.js &amp;lt;DATABASE_PUBLIC_URL&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Great! You should see your table(s) in the Postgres &lt;strong&gt;Data&lt;/strong&gt; tab.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhgh3cgbv2uy5wgd6ul3y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhgh3cgbv2uy5wgd6ul3y.png" alt="Image description" width="800" height="517"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Go to project &lt;strong&gt;Settings&lt;/strong&gt; and scroll down to &lt;strong&gt;Networking&lt;/strong&gt;. Under &lt;strong&gt;Public Networking&lt;/strong&gt;, click on &lt;strong&gt;Generate Domain&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuzqg1q3musvor3megh70.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuzqg1q3musvor3megh70.png" alt="Image description" width="800" height="549"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;That's it! Click on the public domain, and you should be able to see your project working.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Hope this tutorial helps!&lt;/p&gt;

</description>
      <category>postgres</category>
      <category>railway</category>
      <category>node</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
