<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by @seulkiro on Medium]]></title>
        <description><![CDATA[Stories by @seulkiro on Medium]]></description>
        <link>https://medium.com/@seulkiro?source=rss-7bba29b37df6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*a2nEACbC_westxiDsGkrWA@2x.jpeg</url>
            <title>Stories by @seulkiro on Medium</title>
            <link>https://medium.com/@seulkiro?source=rss-7bba29b37df6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 05:05:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@seulkiro/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Deploy Node.js App with GitLab CI/CD]]></title>
            <link>https://medium.com/@seulkiro/deploy-node-js-app-with-gitlab-ci-cd-214d12bfeeb5?source=rss-7bba29b37df6------2</link>
            <guid isPermaLink="false">https://medium.com/p/214d12bfeeb5</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[continuous-deployment]]></category>
            <category><![CDATA[gitlab]]></category>
            <category><![CDATA[heroku]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <dc:creator><![CDATA[@seulkiro]]></dc:creator>
            <pubDate>Sun, 18 Mar 2018 07:16:20 GMT</pubDate>
            <atom:updated>2018-05-28T18:47:27.017Z</atom:updated>
            <content:encoded><![CDATA[<p>I was looking for a tutorial on how to deploy a Node.js application from a GitLab repo with GitLab CI/CD, but couldn’t find one specifically for Node.js. So here is my attempt to write one for future reference and for those who seek for the same information.</p><p>Having spent some time on GitLab documents, it’s actually pretty straight forward. GitLab already has documentations on deploying <a href="https://docs.gitlab.com/ce/ci/examples/test-and-deploy-python-application-to-heroku.html">Python</a> and <a href="https://docs.gitlab.com/ce/ci/examples/test-and-deploy-ruby-application-to-heroku.html">Ruby</a> applications using GitLab CI/CD, which makes the job super easy as it’s almost identical.</p><p>The example below is available at <a href="https://gitlab.com/seulkiro/node-heroku-dpl">https://gitlab.com/seulkiro/node-heroku-dpl</a>/.</p><h3><strong>GitLab Project</strong></h3><p>Before anything, let’s create a GitLab project then check out the repo from it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*woygXux7DRlwoETTkcXbDw.png" /><figcaption>GitLab Project Dashboard</figcaption></figure><p>You can create a project by clicking the <strong><em>New project</em></strong> button. This <a href="https://docs.gitlab.com/ee/gitlab-basics/create-project.html">GitLab document</a> illustrates exactly how to do so. Below is my example of creating a GitLab repo. You would need to replace the repo URL (highlighted in bold and italic) with your project repo URL.</p><p>Don’t worry about the warning. It will disappear once you make first commit.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9bf203e9117a8dee008a6cf978068fb0/href">https://medium.com/media/9bf203e9117a8dee008a6cf978068fb0/href</a></iframe><p>Now, add <strong><em>README</em></strong> and <strong><em>.gitignore</em></strong> files to the project.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cbf573daca7f31ebf9a463bbe7429f46/href">https://medium.com/media/cbf573daca7f31ebf9a463bbe7429f46/href</a></iframe><h3>Node.js Express App</h3><p>With the initial project setup, we are ready to create our Node.js app. I am going to create an Express app as an example.</p><p>Create a brand new project and install express.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3e54f851ca99bc75fa8937c8ad456bf2/href">https://medium.com/media/3e54f851ca99bc75fa8937c8ad456bf2/href</a></iframe><p>It will ask a bunch of questions for the project setup without <strong>-y</strong>. I am using defaults here by adding <strong>-y</strong>. You can change these options later by modifying the package.json file.</p><p>Now, create the entry point of the app by adding the following to <strong><em>index.js</em></strong> in the project’s root directory.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a11874924aab7507f61f99fc649305b2/href">https://medium.com/media/a11874924aab7507f61f99fc649305b2/href</a></iframe><p>The above is a super simple Node.js app defining a route that responds to a GET request to / with a JSON object.</p><p>Let’s run this and see how it works locally.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5842652d97851020d8a875133e3784fa/href">https://medium.com/media/5842652d97851020d8a875133e3784fa/href</a></iframe><p>Open your browser and go to <a href="http://localhost:5000/">http://localhost:5000/</a>. You should see the following hello world JSON object.</p><pre>{<br>  hello: &quot;world&quot;<br>}</pre><h3>Heroku Application Setup</h3><p>Now, let’s create a Heroku application. This will be the application or environment to which we are going to deploy our Node.js application with GitLab CI/CD.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gm35kM0cgfbK1aypuZH1nQ.png" /><figcaption>Heroku Dashboard</figcaption></figure><p>It can be easily created from the Heroku dashboard. All you need is the app name. Note down your app name. It will be used in the GitLab CI/CD configuration file to specify which Heroku app you want to deploy to.</p><p>There is one more thing we need to take care of before setting up GitLab CI/CD. We need to tell Heroku which version of Node.js and NPM it should use when our little Node.js app is deployed.</p><p>We can do this by modifying the <strong><em>package.json</em></strong> file. Let’s update the file by adding the <strong><em>engines</em></strong> and <strong><em>scripts</em></strong> sections just like below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bcbe18b349ff5345991b03f92c16e590/href">https://medium.com/media/bcbe18b349ff5345991b03f92c16e590/href</a></iframe><p>The <strong><em>engines</em></strong> section tells Heroku to use specific versions of Node and NPM for the app. Heroku uses NPM to start the app. So running the app needs to be reflected in the <strong><em>scripts</em></strong> section. Modify the default <strong><em>scripts</em></strong> section so that <strong><em>npm start</em></strong> will kick off our app.</p><p>After this change, you can run the app by the following command.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6560cd49a19264e03d84db9b934ff2d0/href">https://medium.com/media/6560cd49a19264e03d84db9b934ff2d0/href</a></iframe><h3>GitLab CI/CD Configuration File</h3><p>We are almost there.</p><p>We need to create a GitLab CI/CD configuration file in the project’s root directory, which is used by GitLab runner to manage jobs as part of CI/CD, e.g. test, deploying to staging or production environments.</p><p>Add the following to <strong><em>.gitlab-ci.yml</em></strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/068c145e3eb4212dc968d2b6abee6b49/href">https://medium.com/media/068c145e3eb4212dc968d2b6abee6b49/href</a></iframe><p>The YAML file basically tells GitLab to use Node.js docker runner to deploy the app to Hoerku on every push. And shell scripts defined under script will be executed by the runner.</p><p>Note the last shell script. It uses <a href="https://github.com/travis-ci/dpl">dpl</a>, continuous deployment deploy tool, to deploy our app to Heroku. The <strong><em>provider</em></strong> option specifies the provider that we want to deploy to, i.e. Heroku in our case here. The <strong><em>app</em></strong> option sets the Heroku app name. Remember the Heroku app? You need to substitute your Heroku app name here.</p><p>Finally, the <strong><em>api-key</em></strong> option sets the Heroku API key. It is not a good practice to include the API key in the file directly. GitLab provides a way to store it in a protected way.</p><p>Go to your GitLab project. And <strong><em>Settings &gt; CI/CD &gt; Secret Variables</em></strong> is the place where you can store your Heroku API KEY or any other environment variables that the Runner can access to. These variables can be accessed by <strong><em>$ENVIRONMENT_VARIABLE</em></strong> in the YAML file, i.e. <strong><em>.gitlab-ci.yml</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d9VA-o3DNIywYxz7GWjjfw.png" /><figcaption>Setting HEROKU_API_KEY Environment Variable for Runner</figcaption></figure><p>By the way, the Heroku API key is found in the account settings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rkhG1Uq27w0gnnS1jrBoTQ.png" /><figcaption>Heroku API Key under Account Settings</figcaption></figure><h3>Heroku Deployment</h3><p>We are all set for deployment.</p><p>Two more things though. A while back when we created our Node.js app and installed Express, it installed a bunch of dependencies under the <strong><em>node_modules</em></strong> directory. We don’t want to push them to our repo. We can ignore them by adding it to .gitignore file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/754b3f1c136dc874ffc44b347d5034e7/href">https://medium.com/media/754b3f1c136dc874ffc44b347d5034e7/href</a></iframe><p>In addition, in order to make CI/CD to happen on push, shared runners should be enabled in the project’s settings, <strong><em>Settings &gt; CI/CD &gt; Runners settings</em></strong>, unless you plan to use your own runners<em>.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kONf3eka2GAZvb-K1gLlLg.png" /><figcaption>Ensuring that shared runners are enabled</figcaption></figure><p>Let’s commit and push all of our changes.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e4ebdba656114ae37d7769ea8e3070fa/href">https://medium.com/media/e4ebdba656114ae37d7769ea8e3070fa/href</a></iframe><h3>Validation</h3><p>The push should kick off deployment to Heroku. The GitLab project overview will indicate that there is an active deployment with an orange pause icon.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wmFQo-aY1FkDitOHmPhX0A.png" /><figcaption>Project Overview with an Active Deployment</figcaption></figure><p>Clicking the orange pause button should take you to the pipeline. You should be able to see the logs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LxnUvb4qaldWgTBYf-7quA.png" /><figcaption>Deployment Log</figcaption></figure><p>The deployment should succeed shortly after. Note that shared runners may not pick up your deployment if it’s not available.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zor8DxFI_nf9Aa-ducVpOg.png" /><figcaption>Happy Deployment</figcaption></figure><p>Now, check out the Heroku dashboard. The app should be deployed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PtsEBF19_HaQrtIZ40_-Hg.png" /><figcaption>Heroku Dashboard</figcaption></figure><p>You should be able to open the app by clicking the <strong><em>Open app</em></strong> button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GG97e77aco9M6lQ1y29WVA.png" /><figcaption>App in Production!</figcaption></figure><h3>Conclusion</h3><p>GitLab CI/CD is super easy to set up and useful for deploying your changes to different staging environments before production then finally production environment.</p><p>Though I didn’t talk about testing in this post, it would be another great thing about CI/CD because you can test your changes before any deployment. Failure would stop the deployment flow entirely, and you would get notified for it too!</p><p>Heroku supports git repo and even deployments from GitHub out of the box. But I think it’s hard to beat GitLab and Heroku combo which provide unlimited private project, issue tracking, CI/CD, wiki, etc for testing our your ideas and small side projects.</p><p>That’s it. Hope you enjoy the post.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=214d12bfeeb5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>