<?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>DEV Community: Ronald Flores Sequeira</title>
    <description>The latest articles on DEV Community by Ronald Flores Sequeira (@burzumumbra).</description>
    <link>https://dev.to/burzumumbra</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%2F36644%2F1e293421-14ba-45d8-9870-882ff771fdf9.jpg</url>
      <title>DEV Community: Ronald Flores Sequeira</title>
      <link>https://dev.to/burzumumbra</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/burzumumbra"/>
    <language>en</language>
    <item>
      <title>Deploy Nest Js applications to Railway.app</title>
      <dc:creator>Ronald Flores Sequeira</dc:creator>
      <pubDate>Tue, 11 Oct 2022 22:53:03 +0000</pubDate>
      <link>https://dev.to/burzumumbra/deploy-nest-js-applications-to-railwayapp-5ec4</link>
      <guid>https://dev.to/burzumumbra/deploy-nest-js-applications-to-railwayapp-5ec4</guid>
      <description>&lt;p&gt;You can check my original post at &lt;a href="https://ronald-flores-s.medium.com/deploy-nest-js-application-to-railway-app-d21b654a00a4" rel="noopener noreferrer"&gt;Medium&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Deploy Nest Js applications to Railway.app
&lt;/h2&gt;

&lt;p&gt;This would be a short guide to successfully deploying your NodeJS/NestJS app to &lt;strong&gt;Railway&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;I’ll assume that you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Have knowledge of Git.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A &lt;strong&gt;GitHub&lt;/strong&gt; account.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Have knowledge of NodeJS/NestJS.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A &lt;strong&gt;&lt;a href="https://railway.app/" rel="noopener noreferrer"&gt;Railway&lt;/a&gt;&lt;/strong&gt; account.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Steps:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Create a local project.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Upload to a git repository, (&lt;strong&gt;GitHub&lt;/strong&gt; in this case).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create a project in &lt;strong&gt;&lt;a href="https://railway.app/" rel="noopener noreferrer"&gt;Railway&lt;/a&gt;&lt;/strong&gt; and connect it with our repo.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Let’s start by creating a new NestJs:
&lt;/h3&gt;

&lt;p&gt;If you don’t have NestJS CLI installed, just run this command.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i -g **@nestjs/cli**
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;To create a new project, run the following command.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;**nest** new project-name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;That would give us a basic NestJs application that we could deploy to set up the workflow.&lt;/p&gt;

&lt;p&gt;In our project, all we need to do is to open&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./src/**main**.ts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;and update the following line that specifies the port we are running on.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;await app.**listen**(3000);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;to:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;await app.**listen**(process.env.PORT || 3000);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This would take the port from our cloud env or the .env file, just with this our application is ready to run in the &lt;strong&gt;Railway’s&lt;/strong&gt; cloud.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ApNty4v-bJjXVyUr37IuL1A.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ApNty4v-bJjXVyUr37IuL1A.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Upload to GitHub:
&lt;/h3&gt;

&lt;p&gt;Now we can upload our local project to GitHub, just create an empty repo in &lt;strong&gt;GitHub&lt;/strong&gt;, init your local and push your &lt;strong&gt;initial commit&lt;/strong&gt;. &lt;br&gt;
Once you have your project in &lt;strong&gt;Github&lt;/strong&gt;, all that’s left is to connect it to a project in &lt;strong&gt;Railway&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Let’s deploy to Railway:
&lt;/h3&gt;

&lt;p&gt;The first step is to create a new project, from the &lt;strong&gt;GitHub&lt;/strong&gt; repo.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2998%2F1%2AV9k2-ThOX3On8NXhJzrY0Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2998%2F1%2AV9k2-ThOX3On8NXhJzrY0Q.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Selecting our repo:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2998%2F1%2A8OaNWgmcweav1gbpH8kfmg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2998%2F1%2A8OaNWgmcweav1gbpH8kfmg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By default, it would deploy on commits at the &lt;strong&gt;main&lt;/strong&gt; &lt;strong&gt;branch&lt;/strong&gt;, but we can change that in the settings.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3746%2F1%2AgZe1vlaRC1PeLqYiTX0XQA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3746%2F1%2AgZe1vlaRC1PeLqYiTX0XQA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here we can update the branch that would trigger the deployment and also add or generate a domain for this app:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2344%2F1%2AjjMJ9_uGsjvIX93wa-uQ0A.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2344%2F1%2AjjMJ9_uGsjvIX93wa-uQ0A.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Also, we can specify the command to run our app.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2344%2F1%2A6m340tdCHyMIrTB2L9pK3A.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2344%2F1%2A6m340tdCHyMIrTB2L9pK3A.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we have successfully deployed our &lt;strong&gt;NestJs&lt;/strong&gt; app.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2344%2F1%2AT_cybcrrJw5ooc3XE8Bqlg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2344%2F1%2AT_cybcrrJw5ooc3XE8Bqlg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now you could just test the default response from the app:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AC2J-Or_VJoIB85ofZXorlw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AC2J-Or_VJoIB85ofZXorlw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Just remember that you need to update the port to use your &lt;strong&gt;env&lt;/strong&gt;, so you don’t get this error message.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2344%2F1%2ANXlbCaTFIsZU8hI8rKoUCQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2344%2F1%2ANXlbCaTFIsZU8hI8rKoUCQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Bonus:
&lt;/h3&gt;

&lt;p&gt;Since the Port &lt;strong&gt;env&lt;/strong&gt; variable is created by &lt;strong&gt;Railway&lt;/strong&gt; we don’t need to add any variable for this example, but in case you need to add them, just go to the &lt;strong&gt;Variables&lt;/strong&gt; tab and add them.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2354%2F1%2AheUnM7Qf3S3-4ujBPzA5BQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2354%2F1%2AheUnM7Qf3S3-4ujBPzA5BQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2354%2F1%2ABEcACGkAnrWn7Docq6w7TQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2354%2F1%2ABEcACGkAnrWn7Docq6w7TQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Recap:
&lt;/h3&gt;

&lt;p&gt;With a few steps, you can have your &lt;strong&gt;NestJs&lt;/strong&gt; Application up and running in &lt;strong&gt;&lt;a href="https://railway.app/" rel="noopener noreferrer"&gt;Railway&lt;/a&gt;&lt;/strong&gt;, just remember to point your port to the &lt;strong&gt;env&lt;/strong&gt; so you don’t have an error, the app would be running, but not connecting to the open port.&lt;/p&gt;

</description>
      <category>nestjs</category>
      <category>node</category>
      <category>railway</category>
      <category>deploy</category>
    </item>
  </channel>
</rss>
