<?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" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ Caddy - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ Caddy - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Mon, 24 Aug 2026 04:28:18 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/caddy/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How to Deploy a Node.js Application on AWS ]]>
                </title>
                <description>
                    <![CDATA[ Cloud platforms and infrastructure allow you to easily deploy and host backend services and applications. In this article, you’ll learn how to run a Node.js/Express application away from the confines of your local personal computer to make it accessi... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-deploy-a-nodejs-application-on-aws/</link>
                <guid isPermaLink="false">67ed67823b8c37d192779b99</guid>
                
                    <category>
                        <![CDATA[ AWS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Node.js ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Caddy ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Oluwatobi ]]>
                </dc:creator>
                <pubDate>Wed, 02 Apr 2025 16:36:18 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/upload/v1743611764466/96a89440-1c72-4ac0-861d-0ea29aeb90bf.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Cloud platforms and infrastructure allow you to easily deploy and host backend services and applications. In this article, you’ll learn how to run a Node.js/Express application away from the confines of your local personal computer to make it accessible globally on the cloud. We’ll use Amazon Web Services to do this.</p>
<p>But before we get started, here are some prerequisites for the tutorial:</p>
<ul>
<li><p>An active AWS account</p>
</li>
<li><p>Basic beginner to intermediate knowledge of Node.js and Express</p>
</li>
<li><p>Knowledge of Linux commands</p>
</li>
</ul>
<p>With that, let's get started.</p>
<h3 id="heading-expected-takeaways">Expected takeaways</h3>
<p>At the end of this guide, you should be equipped with basic knowledge of:</p>
<ul>
<li><p>AWS EC2 and other hosting mediums</p>
</li>
<li><p>Linux</p>
</li>
<li><p>Networking</p>
</li>
</ul>
<h2 id="heading-table-of-contents">Table Of Contents</h2>
<ol>
<li><p><a class="post-section-overview" href="#heading-introduction">Introduction</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-set-up-aws">How to Set Up AWS</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-deploy-the-nodejs-application">How to Deploy the Node.js Application</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-is-caddy">What is Caddy?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-setting-up-caddy">Setting Up Caddy</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-additional-information">Additional Information</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-conclusion">Conclusion</a></p>
</li>
</ol>
<h2 id="heading-introduction">Introduction</h2>
<p>Deploying backend applications on the cloud is pretty straightforward thanks to the advent of public cloud service providers like AWS.</p>
<p>You can host these applications on the cloud using several methods, depending on your application’s complexity and use cases.</p>
<p>For the AWS platform, you could deploy on:</p>
<ul>
<li><p><strong>AWS EC2 (Elastic Cloud Compute)</strong>: This option lets you deploy a virtual operating system server which serves as the backbone on which the application is hosted. It's suitable for complex monolithic backend applications.</p>
</li>
<li><p><strong>AWS Lambda</strong>: This is popularly termed AWS serverless which allows speedy execution of functions when needed. It doesn’t require consistent uptime hours. This is more suited for simple backend functions with specific use cases.</p>
</li>
</ul>
<p>For the purpose of this tutorial, we will be exploring the AWS EC2 option for deploying a Node.js application. We will also cover using a dedicated reverse proxy to give you easy access to your deployed application.</p>
<h2 id="heading-how-to-set-up-aws">How to Set Up AWS</h2>
<p>Firstly, I assume that you have an AWS account (minimum free tier). If you don't, kindly <a target="_blank" href="https://portal.aws.amazon.com/billing/signup">navigate here</a> and set up your account.</p>
<p>After you have logged in successfully, you will have access to all the various AWS products available. Search for AWS EC2 on the search bar. Once you click that, you will see the EC2 dashboard.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1742697716239/8020771d-3941-490b-8468-36d82e5e8c24.png" alt="EC2 dashoard" class="image--center mx-auto" width="1189" height="283" loading="lazy"></p>
<p>We’ll now create a new EC2 instance.</p>
<p>For cost-effectiveness and simplicity, we’ll use the free tier options made available by AWS. First, you’ll begin by creating an instance name. You can set this according to your preference.</p>
<p>Next, you’ll choose a specific operating system to serve as the operating system for your virtual sever. In this tutorial, I’ll be opting for the Ubuntu Linux distro.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1742826868559/a08cbc5c-e35f-4264-ab17-6746dfea74d8.png" alt="Operating system images" class="image--center mx-auto" width="1140" height="480" loading="lazy"></p>
<p>Next you’ll choose a compatible compute instance type. AWS provides free access to <em>t2.micro</em> and <em>t3.micro</em> which will suffice for hosting your application.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1742697788341/b4462135-7657-4608-a339-3a18d7187db1.png" alt="EC2 instance type" class="image--center mx-auto" width="774" height="275" loading="lazy"></p>
<p>This part allows you to configure <code>ssh</code> to enable remote access to your server. In my case, I opted out since I intend to use the EC2 connect console option.</p>
<p>After completing the steps above you’ll configure the network settings. This is where your knowledge of Networking will come in handy.</p>
<p>Automatically, AWS creates and assigns a virtual private cloud network to your soon-to-be-launched EC2 instance. You can customize it to suit your purposes, but for this tutorial, we’ll go with the default VPC assigned. Also, we’ll leave the subnet and auto-assign IP the way it is.</p>
<p>For the firewall settings, it comes with two options: create a security group or use an existing security group. For ease of use with the EC2 instance you’ll create, you can configure the Firewall setting by creating a new security group, specifying the network types, and restricting the IP address of users trying to access the EC2 instance you’ll create. Further, you still might want to use any of your preformed firewall configurations in the <em>“use existing security group</em>” option.</p>
<p>You can leave other sections as they are, and then go ahead and create your EC2 instance.</p>
<p>Once you’ve successfully created the EC2 instance, you can connect to the instance via the options provided.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1742697864497/40b77502-7f7b-4f76-9e8d-fbabfe3d5755.png" alt="EC2 connect options" class="image--center mx-auto" width="1184" height="561" loading="lazy"></p>
<p>For the purpose of this tutorial, you’ll use the EC2 instance connect option to access your EC2 instance. Once you’ve clicked on the button, you will then be brought into the Linux console.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1742826982246/5c4f67d6-11f1-4346-9c33-a3fbb969bbba.png" alt="Linux console" class="image--center mx-auto" width="1315" height="479" loading="lazy"></p>
<p>To begin, you’ll immediately update your operating system packages using the <code>sudo</code> command.</p>
<p>The <code>sudo apt update</code> command will get this done. With your packages up to date, now you can install the relevant packages needed to get your Node.js application powered on: the <em>Node.js installer package</em> and <em>npm</em> (node package manager) tools, respectively.</p>
<p>Then install them using the <code>sudo apt install nodejs npm</code> command.</p>
<p>With this done, you’ve gotten everything ready to run your application.</p>
<h3 id="heading-how-to-deploy-the-nodejs-application">How to Deploy the Node.js Application</h3>
<p>We’ll use a simple Node.js/Express application in this tutorial. You can find the source code <a target="_blank" href="https://github.com/rat9615/simple-nodejs-app">here</a>. Inside your EC2 console, clone the application source code using the <code>git clone</code> <a target="_blank" href="https://github.com/rat9615/simple-nodejs-app"><code>https://github.com/rat9615/simple-nodejs-app</code></a> command.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1742697610337/b777176a-d97e-4289-bb43-002d4b80f88c.png" alt="This image shows the application code cloning process using git" class="image--center mx-auto" width="638" height="174" loading="lazy"></p>
<p>After successfully cloning the code project, execute the command <code>cd simple-nodejs-app</code> to navigate into the code folder directory. Now, install the various necessary application dependencies that are included in the code project’s <code>package.json</code> file by executing <code>npm install</code>:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1742697545681/8c99ae1f-8d4e-4116-944d-5ce0d7613550.png" alt="This image shows installing all the packages needed to run the backend application. The command executed is npm install" class="image--center mx-auto" width="973" height="461" loading="lazy"></p>
<p>After completing the above steps, the <code>npm start</code> command will bring your application to life. You should then see a success message on your screen.</p>
<p>But if you navigate to the EC2 instance public IP address with the Instance IP address sub-port 3000, you’ll still see an error – so what haven’t we completed?</p>
<p>Here is where your knowledge of Networking comes in again. Now, navigate back to your cloud EC2 compute dashboard and go to the security groups. These contain and enforce your inbound and outbound rules.</p>
<p>But before we go on, what are inbound and outbound rules?</p>
<ul>
<li><p><strong>Inbound rules</strong> allow you to easily configure access to the cloud resource via any route. They ensure that only those who are expressly authorized are granted access. These routes include, but are not limited to, SSH, HTTP, HTTPS, and TCP.</p>
</li>
<li><p><strong>Outbound rules</strong> allow you to easily configure the flow of cloud resources information to the external world. Only authorized Internet protocol addresses will get access to the information requested.</p>
</li>
</ul>
<p>So now, you’ll be creating a new inbound rule which will give you access to the backend API endpoint at port 3000:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1743174093701/0d31d813-58cb-40d3-8559-71974aefaefd.png" alt="In this image, we are defining relevant inbound rules for our machine " class="image--center mx-auto" width="1335" height="474" loading="lazy"></p>
<p>Clicking on the Add rule button allows you to add new network access routes on your EC2 machine. Already setup are the HTTP and TCP traffic routes.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1743174075948/e0d6a6c9-3f7a-48bd-804b-083eb1d7514f.png" alt="This shows the various networking ports and routes on our AWS machine" class="image--center mx-auto" width="1118" height="181" loading="lazy"></p>
<p>The image above highlights all the included inbound rules in a demo application. Now let’s return to configuring our Networking settings.</p>
<p>Within the security groups in your dashboard, click on the <strong>Add rule</strong> button at the end of the page.</p>
<p>Select the TCP network type, set the host to <code>0.0.0.0.0/0</code>, and set the port to port 3000. Lastly, to complete the IP address request setup, just click on the “allow from anywhere” option. Save the rule and refresh your tab. Within a few minutes, the endpoint will be made available on port 3000.</p>
<p>To see the application live in action, click on the external IP address of the EC2 instance and add a suffix port 3000 to view the backend application interface. And violà, your application should now be live.</p>
<p>But that’s not all – it's inconvenient to include the sub-port number while browsing the IP address. So you’ll need a compatible effective reverse proxy tool which routes any information from port 3000 to port 80 (which is a general port). A reverse proxy in this scenario routes and forwards requests from clients to a server serving as a protective intermediary. To do this, you can use a tool called Caddy.</p>
<h2 id="heading-what-is-caddy">What is Caddy?</h2>
<p>Caddy is a flexible, beginner-friendly, open-source tool which offers reverse proxy, load balancing, and caching features in addition to its role as a web server. It has an extensive user guide and documentation which you can lookup <a target="_blank" href="https://caddyserver.com/docs/">here</a>.</p>
<p>Now, let’s set up Caddy on your EC2 instance.</p>
<h2 id="heading-setting-up-caddy">Setting up Caddy</h2>
<h3 id="heading-install-caddy">Install Caddy</h3>
<p>First, you’ll need to install Caddy on your Linux OS. You can do this by executing <code>sudo apt install caddy</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1742697469605/cf58d75f-ed72-4078-8e45-30b7da0916b1.png" alt="Caddy tool installation process" class="image--center mx-auto" width="656" height="422" loading="lazy"></p>
<p>After completing the installation process, the above image should be what you should see on your screen. Once you’ve done this, make sure that Caddy is enabled and powered on by running this command:</p>
<p><code>caddy run</code></p>
<p>After running the command above, the Caddy tool should be enabled and active. Then you should see the below image on your screen:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1742697342473/be0499f4-6a0f-406b-87d9-0688e56d8783.png" alt="Current status of the Caddy tool " class="image--center mx-auto" width="1076" height="423" loading="lazy"></p>
<p>Next, navigate to the external IP address available on your EC2 instance. There, displayed on the screen, should be the Caddy home page.</p>
<h3 id="heading-configure-caddy">Configure Caddy</h3>
<p>Going back to your console, you’ll need to tweak the Caddy configuration file to enable the reverse proxy of <strong>port 3000</strong> to the default port <strong>80</strong>.</p>
<p>To access the config file, navigate to the file from the route directory via the <code>cd /etc/caddy/Caddyfile</code> command.</p>
<p>You can then use the <code>sudo nano</code> command to open the config file for editing. The <code>sudo</code> prefix gives you admin privileges that allow you to make necessary changes on the config file.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1742697233724/cf694df5-74bc-4975-b3e7-c0414fb68646.png" alt="Caddy configuration file" class="image--center mx-auto" width="1160" height="458" loading="lazy"></p>
<p>Within the port 80 section in the config file, add this line of code:</p>
<p><code>reverse_proxy :3000</code></p>
<p>Save the file – and now you’re done. You can restart the Caddy tool to reflect the new settings by running <code>sudo systemctl restart caddy.</code> Refreshing the IP address will display your powered-on Node.js application. With this, you’ve successfully hosted your Node.js application on EC2 and utilized a reverse proxy tool to bring it to life.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1742827013554/f99be1e5-bfc6-444c-b620-9c47ae43dc3a.png" alt="Project's Home page" class="image--center mx-auto" width="687" height="187" loading="lazy"></p>
<h2 id="heading-additional-information">Additional Information</h2>
<p>Going forward, it's good practice to enable DNS features with domain name customization, as users may not always remember the IP address. You can also further increase your expertise in deploying backend applications by experimenting with powering backend functions with AWS lambda.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>With this, we have come to the end of the tutorial. I hope you’ve learned about AWS operations and setting up a backend application on the cloud. You can also reach out to me on my blog and check out my other articles <a target="_blank" href="http://portfolio-oluwatobi.netlify.app">here</a>. Till next time, keep on coding!</p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
