<?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: Hayley van Waas</title>
    <description>The latest articles on Forem by Hayley van Waas (@hayleycodes).</description>
    <link>https://forem.com/hayleycodes</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%2F333613%2F610bf383-91e6-49dd-88b0-60e236afe964.jpg</url>
      <title>Forem: Hayley van Waas</title>
      <link>https://forem.com/hayleycodes</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/hayleycodes"/>
    <language>en</language>
    <item>
      <title>Deploying a Node.js site to Vultr</title>
      <dc:creator>Hayley van Waas</dc:creator>
      <pubDate>Fri, 04 Sep 2020 05:51:03 +0000</pubDate>
      <link>https://forem.com/hayleycodes/deploying-a-node-js-site-to-vultr-j8d</link>
      <guid>https://forem.com/hayleycodes/deploying-a-node-js-site-to-vultr-j8d</guid>
      <description>&lt;p&gt;There are plenty of different tools and services that you can use to deploy your projects these days. Lately I've been heading into Heroku and AWS territory, but a service I really like using for simple projects is Vultr.&lt;/p&gt;

&lt;h2&gt;
  
  
  So what is Vultr?
&lt;/h2&gt;

&lt;p&gt;Vultr is a server hosting platform, but let's put that into context. I assume you got to this blog post because you are trying to work out how to deploy a Node.js project. So at the moment, you type something like &lt;code&gt;npm start&lt;/code&gt; and your server starts running and you can view your project. Vultr is a company that has many physical computers lying in wait for you to use. You "upload" your project onto one (or more) of those computers, tell them how to start the server, and bam, you can see your project running on the internets, rather than just locally on your machine.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's the difference between Vultr and other cloud hosting services? ☁️
&lt;/h2&gt;

&lt;p&gt;Look, basically nothing. On a surface level you could pick anyone of the major competitors (Digital Ocean, AWS, Azure, Google Cloud) and probably get done what you want to get done. The question though is do you need the extra bells and whistles? For my portfolio website I don't want or need anything fancy, e.g. I don't need it to auto scale to use more resources when it's busy, because at most there are only ever 2 people on my site anyway 🤷‍♀️. What I do need is the bare bones, and clear documentation on how to set that up. I might also consider Digital Ocean, because they are basically interchangeable in my eyes (in fact the first time I set a project up on Vultr, I was flicking between both Vultr and Digital Ocean documentation).&lt;/p&gt;

&lt;p&gt;However the reason I would use Vultr rather than Heroku for this kind of site, is because Heroku has a bit of magic that takes care of a lot of steps for you, but with Vultr you have to set up and configure everything. You might be thinking, "🤔 Huh? Why is that a good thing?" This is usually where someone says "oh because it gives you lots of control over every step", what does that mean? Yea I didn't know either, but now that I have been using Vultr for a number of years, I get it.&lt;/p&gt;

&lt;p&gt;For the longest time I just couldn't understand how the process of deploying things works. "Put it on the cloud"....ok. "Dynamically spins up servers"....cool story. "Set up https"...all right.... When I started deploying this on Vultr I suddenly understood what all those things mean, what talks to what, and more importantly when I inevitably screw something up (or it just breaks all by itself, because that happens) I now actually know what part is broken and what to frantically Google to fix it.&lt;/p&gt;

&lt;h2&gt;
  
  
  I'm convinced, let's do this! 👊
&lt;/h2&gt;

&lt;p&gt;Hurrah!&lt;/p&gt;

&lt;h3&gt;
  
  
  Prerequisites
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Have a Node.js website in a Git repository and ready to go.&lt;/li&gt;
&lt;li&gt;Have a domain name purchased and ready to use.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Step 1
&lt;/h3&gt;

&lt;p&gt;Create an account with Vultr. Preferably you'll use &lt;a href="https://www.vultr.com/?ref=7658295" rel="noopener noreferrer"&gt;this link&lt;/a&gt; so that I can get $10 credit from you signing up (come on, you're reading this for free, so help a peep out!).&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2
&lt;/h3&gt;

&lt;p&gt;Once you are signed up, logged in and on your dashboard, go to the Products page and find the button that says "Deploy New Server".&lt;/p&gt;

&lt;p&gt;This will take you to a page that looks something like this:&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ffgq9hczr1oasay2bnkg4.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ffgq9hczr1oasay2bnkg4.png" alt="Screenshot of settings page for new server setup on Vultr."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now there are obviously a lot of options here (recall the rambling earlier), so pick what is suitable for you, or just follow me if you have no idea what that is. There will be different commands for different operating systems, so I suggest you pick the same option as me for that (Ubuntu).&lt;/p&gt;

&lt;p&gt;I'm going to select the following settings:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Cloud Compute&lt;/li&gt;
&lt;li&gt;Sydney (pick the option that is closest to you)&lt;/li&gt;
&lt;li&gt;64 bit OS&lt;/li&gt;
&lt;li&gt;Ubuntu 20.04x64 (latest at time of writing)&lt;/li&gt;
&lt;li&gt;25 GB - this is the smallest. If you don't know what you need, just pick this one since it is the cheapest, and if it turns out that's not enough then it is easy to upgrade it later.&lt;/li&gt;
&lt;li&gt;Leave the next few fields blank, up to server hostname. Give it a name that is meaningful to your and your project, for example, for my portfolio site mine is called "personal-website"&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Click "Deploy Now" and it will take you back to your dashboard where you will see the new server is busy being installed.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fen0ip43lxw52pwimh1ju.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fen0ip43lxw52pwimh1ju.png" alt="Screenshot of dashboard on Vultr showing a server installation progress."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Wait for it to finish installing (a few minutes at most).&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3
&lt;/h3&gt;

&lt;p&gt;Click on the server that you just created, it will take you to an overview page for that server. Copy the IP address for the server.&lt;/p&gt;

&lt;p&gt;Then open up terminal and type the following to log into the server as the root user, (replacing &lt;code&gt;&amp;lt;ip address&amp;gt;&lt;/code&gt; with the IP address that you copied:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="nv"&gt;$ &lt;/span&gt;ssh root@&amp;lt;ip address&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You'll be prompted for a password, use the password provided on the overview page in Vultr.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4
&lt;/h3&gt;

&lt;p&gt;Create a new user. This is the username and password that you'll use to log into the server from here on in, so make sure to pick something sensible (and even better, store it in your password manager if you use one).&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="nv"&gt;$ &lt;/span&gt;adduser &amp;lt;my-new-user&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;After entering your password you can leave the other prompts blank.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 5
&lt;/h3&gt;

&lt;p&gt;Add the new user to a group and give sudo access:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="nv"&gt;$ &lt;/span&gt;usermod &lt;span class="nt"&gt;-aG&lt;/span&gt; &lt;span class="nb"&gt;sudo&lt;/span&gt; &amp;lt;my-new-user&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Logout and log back in as the new user:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;logout&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;ssh &amp;lt;my-new-user&amp;gt;@&amp;lt;ip address&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Step 6
&lt;/h3&gt;

&lt;p&gt;Update any package info on the server then install Nginx:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get update
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get &lt;span class="nb"&gt;install &lt;/span&gt;nginx 


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Nginx is what is going to do the heavy lifting for getting people to your site. Every time someone comes to your site, Nginx is going to intercept that request, then talk to your Node.js server to work out what to send back. (The term to look up for more information is "reverse proxy"). There are a few other things it is going to do to, but that's the main task that we are interested in for the scope of this tutorial.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 7
&lt;/h3&gt;

&lt;p&gt;Next we're going to tweak the configuration of the firewall on the Ubuntu server so that Nginx can do it's thing, and so that you can SSH back into your server:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;ufw allow &lt;span class="s1"&gt;'Nginx HTTP'&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;ufw allow &lt;span class="s1"&gt;'OpenSSH'&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;ufw &lt;span class="nb"&gt;enable&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;systemctl status nginx


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The last command will give a few lines of output, you just need to check that it says &lt;code&gt;active (running)&lt;/code&gt; in there somewhere.&lt;/p&gt;

&lt;p&gt;If you have any issues with Nginx in the next few steps, here are some handy commands to stop, start, restart and reload Nginx:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl stop nginx
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl start nginx
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl restart nginx
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl reload nginx


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Step 8 🔒
&lt;/h3&gt;

&lt;p&gt;This is the step where we set up SSL certificates, i.e. this is where we'll make a connection between your domain name and your server, and also set it up to use HTTPS.&lt;/p&gt;

&lt;p&gt;First, install certbot:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;certbot python3-certbot-nginx
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;nano /etc/nginx/sites-available/default


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This will open a file in the nano text editor. There are a lot of comments in the file, you are looking for the line that says:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

server_name _&lt;span class="p"&gt;;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Replace the underscore with your domain name, so your end result will look something like:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

server_name mydomain.com www.mydomain.com&lt;span class="p"&gt;;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Save and exit the file.&lt;/p&gt;

&lt;p&gt;Verify the file is all good and reload:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;nginx &lt;span class="nt"&gt;-t&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl reload nginx


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Modify the Nginx configuration:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;ufw allow &lt;span class="s1"&gt;'Nginx Full'&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;ufw delete allow &lt;span class="s1"&gt;'Nginx HTTP'&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;At this point you will need to set the DNS records in your domain registrar.&lt;/p&gt;

&lt;p&gt;Set the A Record Host to &lt;code&gt;@&lt;/code&gt; and the Value to the IP address for your server (the one you copied way back in step 3).&lt;/p&gt;

&lt;p&gt;Set the CNAME record Host to &lt;code&gt;www&lt;/code&gt; and the Value to your domain name with a &lt;code&gt;.&lt;/code&gt; suffix, e.g. &lt;code&gt;mydomain.com.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Create the SSL certificate:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;certbot &lt;span class="nt"&gt;--nginx&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; &amp;lt;mydomain&amp;gt; &lt;span class="nt"&gt;-d&lt;/span&gt; www.&amp;lt;mydomain&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;When prompted, select 2 to set it to automatically redirect to https.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 9
&lt;/h3&gt;

&lt;p&gt;Install Node:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; ~/
&lt;span class="nv"&gt;$ &lt;/span&gt;curl &lt;span class="nt"&gt;-sL&lt;/span&gt; https://deb.nodesource.com/setup_10.x &lt;span class="nt"&gt;-o&lt;/span&gt; nodesource_setup.sh
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;bash nodesource_setup.sh
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get &lt;span class="nb"&gt;install &lt;/span&gt;nodejs
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get &lt;span class="nb"&gt;install &lt;/span&gt;build-essential


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Step 10
&lt;/h3&gt;

&lt;p&gt;Clone your repository and navigate into it:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="nv"&gt;$ &lt;/span&gt;git clone https://github.com/&amp;lt;my-username&amp;gt;/&amp;lt;repo-name&amp;gt;.git
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; &amp;lt;repo-name&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Install your dependencies and make sure the server can run:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="nv"&gt;$ &lt;/span&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;npm start


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Step 11
&lt;/h3&gt;

&lt;p&gt;Install and set up pm2. pm2 is responsible for making sure your site keeps running.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-g&lt;/span&gt; pm2
&lt;span class="nv"&gt;$ &lt;/span&gt;pm2 start &amp;lt;server file&amp;gt;.js
&lt;span class="nv"&gt;$ &lt;/span&gt;pm2 startup systemd


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;.js is the name of the file that runs your server, (commonly just &lt;code&gt;server.js&lt;/code&gt;).&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="nv"&gt;$ &lt;/span&gt;pm2 startup systemd


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;A command will be given in the output from the above command, run that command. (It will looks similar to the following)&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="nb"&gt;sudo env &lt;/span&gt;&lt;span class="nv"&gt;PATH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$PATH&lt;/span&gt;:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd &lt;span class="nt"&gt;-u&lt;/span&gt; server &lt;span class="nt"&gt;--hp&lt;/span&gt; /home/server


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Step 12
&lt;/h3&gt;

&lt;p&gt;Back to Nginx!&lt;/p&gt;

&lt;p&gt;Open the Nginx configuration file we were working in earlier:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;nano /etc/nginx/sites-available/default


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Replace the location block with:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

location / &lt;span class="o"&gt;{&lt;/span&gt;
    proxy_pass http://localhost:&amp;lt;your port &lt;span class="o"&gt;(&lt;/span&gt;probably 3000&lt;span class="o"&gt;)&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    proxy_http_version 1.1&lt;span class="p"&gt;;&lt;/span&gt;
    proxy_set_header Upgrade &lt;span class="nv"&gt;$http_upgrade&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    proxy_set_header Connection &lt;span class="s1"&gt;'upgrade'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    proxy_set_header Host &lt;span class="nv"&gt;$host&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    proxy_cache_bypass &lt;span class="nv"&gt;$http_upgrade&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Test all is well and restart:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;nginx &lt;span class="nt"&gt;-t&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl restart nginx


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Step 13 🎉
&lt;/h3&gt;

&lt;p&gt;Done! You should now be able to go to your domain in any web browser and see your site!&lt;/p&gt;
&lt;h3&gt;
  
  
  Debugging
&lt;/h3&gt;

&lt;p&gt;If you have any issues, then I highly recommend the tutorials from Vultr (&lt;a href="https://www.vultr.com/docs/category/node-js/" rel="noopener noreferrer"&gt;here&lt;/a&gt;) and DigitalOcean (&lt;a href="https://www.digitalocean.com/community/tutorials" rel="noopener noreferrer"&gt;here&lt;/a&gt;).&lt;/p&gt;
&lt;h3&gt;
  
  
  Updating
&lt;/h3&gt;

&lt;p&gt;When you want to update your website in future, all you need to do is pull the latest changes from git and then restart pm2:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="nv"&gt;$ &lt;/span&gt;git pull
&lt;span class="nv"&gt;$ &lt;/span&gt;pm2 restart &amp;lt;app name&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>beginners</category>
      <category>node</category>
      <category>devops</category>
    </item>
    <item>
      <title>Deploying a Strapi project on Heroku</title>
      <dc:creator>Hayley van Waas</dc:creator>
      <pubDate>Fri, 22 May 2020 09:53:59 +0000</pubDate>
      <link>https://forem.com/hayleycodes/deploying-a-strapi-project-on-heroku-1aba</link>
      <guid>https://forem.com/hayleycodes/deploying-a-strapi-project-on-heroku-1aba</guid>
      <description>&lt;p&gt;Prerequisites:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Have an account with &lt;a href="https://www.heroku.com/home"&gt;Heroku&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Have a Strapi project, which uses a Postgres database, in a git repository&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Strapi runs on a Node server and has a database (I chose Postgres). This tutorial focuses on Strapi in particular, but this really could apply to any other Node + Postgres project.&lt;/p&gt;

&lt;p&gt;I don't know about you, but as I get further along in my career as a developer I am finding that there are more and more things that I want/need to know. For me, I have a massive blind spot when it comes to deploying anything. It makes me terribly impatient and I hate it.&lt;/p&gt;

&lt;p&gt;I used to absolutely despise cooking, so one summer I decided that I was going to get good at it. My theory was that maybe if I was good at it, I wouldn't hate it so much. That theory turned out to be absolutely true, and not only do I love cooking now, but I also combined that love with coding and have my own recipe site! (It's called &lt;a href="https://www.hayleyshealthfoods.com/?utm_source=dev-to&amp;amp;utm_medium=blog&amp;amp;utm_campaign=deploying-strapi-on-heroku"&gt;Hayley's Health Foods&lt;/a&gt;, if you're interested). Anyway, a couple of months ago I decided that maybe it was time to take the same approach with deployment. Maybe if it wasn't so hard, it wouldn't be such a chore. So here we are, one of the best ways to learn how to do something is to teach someone else, so welcome to this tutorial of how to deploy a Strapi application on Heroku, with the Heroku Postgres add-on.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Create a strapi project
&lt;/h2&gt;

&lt;p&gt;Hopefully you have already done this. Otherwise either:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;hop over to &lt;a href="https://hayley.codes/blog/using-strapi-to-create-a-blog?utm_source=dev-to&amp;amp;utm_medium=blog&amp;amp;utm_campaign=deploying-strapi-on-heroku"&gt;https://hayley.codes/blog/using-strapi-to-create-a-blog&lt;/a&gt; to learn about Strapi, or&lt;/li&gt;
&lt;li&gt;use &lt;code&gt;yarn create strapi-app my-project&lt;/code&gt; (and selecting Postgres as the database type for this tutorial).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 2: Configure the production database settings
&lt;/h2&gt;

&lt;p&gt;In &lt;code&gt;config &amp;gt; environments &amp;gt; production &amp;gt; database.json&lt;/code&gt; set the client, host, port, database, username and password settings.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"defaultConnection"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"default"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"connections"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"default"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"connector"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"bookshelf"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"settings"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"client"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"postgres"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"host"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"${process.env.DATABASE_HOST}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"port"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"${process.env.DATABASE_PORT}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"database"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"${process.env.DATABASE_NAME}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"username"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"${process.env.DATABASE_USERNAME}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"password"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"${process.env.DATABASE_PASSWORD}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"options"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If these &lt;code&gt;process.env.variable&lt;/code&gt; lines are new to you, what we are doing is accessing environment variables that we will set in Heroku. This is a way to avoid posting sensitive credentials directly in git where everyone can see it. Even if your repository is private, it's definitely not good practice to commit credentials.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Set up Heroku
&lt;/h2&gt;

&lt;p&gt;If you haven't already done so, head over to &lt;a href="https://signup.heroku.com/"&gt;https://signup.heroku.com/&lt;/a&gt; to make a free account.&lt;/p&gt;

&lt;p&gt;Download and install the Heroku CLI for your operating system. I'm using Homebrew:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;brew tap heroku/brew &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; brew &lt;span class="nb"&gt;install &lt;/span&gt;heroku
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Or go to &lt;a href="https://devcenter.heroku.com/articles/heroku-cli#download-and-install"&gt;Heroku&lt;/a&gt; for instructions specific to your OS.&lt;/p&gt;

&lt;p&gt;Once you've got an account and have the CLI installed, use the following command to log in:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;heroku login
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Create a new project on Heroku:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;heroku create your-project-name
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Add the Heroku Postgres &lt;a href="https://elements.heroku.com/addons/heroku-postgresql"&gt;add-on&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;heroku addons:create heroku-postgresql:hobby-dev
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The addon comes with a free tier which includes up to 10,000 rows in the database, perfect if you're setting up something small.&lt;/p&gt;

&lt;p&gt;The add-on automatically exposes the database credentials into a single environment variable accessible by your app. View them using the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;heroku config
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This will produce a long string for all of the variables, which can be read like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;postgres:// USERNAME : PASSWORD @ HOST : PORT / DATABASE_NAME
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Use these variables to set each of the following environment variables for your strapi project:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;DATABASE_USERNAME&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;DATABASE_PASSWORD&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;DATABASE_HOST&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;DATABASE_PORT&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;DATABASE_NAME&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Using the following command for each:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;heroku config:set &lt;span class="nv"&gt;VARIABLE_NAME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;variable_value
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;e.g.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;heroku config:set &lt;span class="nv"&gt;DATABASE_PORT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;5432
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If you did not originally install Strapi with PostgresSQL you will need to install the pg module now:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;pg
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Deploy🤞
&lt;/h2&gt;

&lt;p&gt;Deploy the project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;git push heroku master
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Once it has completed deployment you can open your project using&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;heroku open
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You did it! 🎉&lt;/p&gt;

&lt;p&gt;...hopefully.&lt;/p&gt;

&lt;h2&gt;
  
  
  Troubleshooting
&lt;/h2&gt;

&lt;p&gt;One of the reasons I hate deploying stuff is it never seems to work first time. So if you've followed this tutorial and something didn't work out right, there a couple things to do first:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Confirm you can run the app locally. If it doesn't work locally, there's no way it's going to work on production.&lt;/li&gt;
&lt;li&gt;Check you have correctly set all the environment variables in heroku. You can do this by going to &lt;a href="https://dashboard.heroku.com/"&gt;https://dashboard.heroku.com/&lt;/a&gt;, clicking your app, then head to Settings where you will find a button labelled "Reveal Config Vars" - make sure they match what you can see in the terminal (recall &lt;code&gt;heroku config&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Read the logs. You can see the most recent logs using &lt;code&gt;heroku logs --tail&lt;/code&gt; There's a lot of junk in there, but more often than not there is a single line with an error message you can Google.&lt;/li&gt;
&lt;li&gt;Google it.&lt;/li&gt;
&lt;li&gt;Ask the community. Stack Overflow and Twitter are the places to be for us developers 😊&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>strapi</category>
      <category>heroku</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Using Strapi to create a blog</title>
      <dc:creator>Hayley van Waas</dc:creator>
      <pubDate>Sat, 16 May 2020 06:54:18 +0000</pubDate>
      <link>https://forem.com/hayleycodes/using-strapi-to-create-a-blog-4123</link>
      <guid>https://forem.com/hayleycodes/using-strapi-to-create-a-blog-4123</guid>
      <description>&lt;p&gt;I decided to make a blog on my personal site (so original, I know), but I also had two other pretty major side projects going on at the time (and basically always). So whatever time I could find to work on it, I wanted to be dedicated to the actual blog posts, rather than implementation. This meant that I needed something fast and easy to set up to handle the database side of things. In other words, I needed a CMS that I could add to my existing website.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a CMS?
&lt;/h2&gt;

&lt;p&gt;CMS = Content Management System.&lt;/p&gt;

&lt;p&gt;A CMS is an interface for adding/editing/deleting content on a website. WordPress is a very commonly used CMS.&lt;/p&gt;

&lt;p&gt;Since I wanted a CMS that I could add to an existing site, I wanted to find a &lt;em&gt;headless&lt;/em&gt; CMS. This is a CMS that separates the front end from the back end. You build your front end, and then talk to the back end via a REST API. I had my front end ready to go, so the back end was all I needed.&lt;/p&gt;

&lt;p&gt;Enter &lt;a href="https://strapi.io/" rel="noopener noreferrer"&gt;strapi&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Strapi
&lt;/h2&gt;

&lt;p&gt;There were no shortage of results for headless CMS', but a lot of them are paid and definitely aimed at users rather than developers. Strapi is a free, self hosted, open source CMS.&lt;/p&gt;

&lt;p&gt;Free has pros and cons. On the one hand, I saved $$$, on the other hand, it means that I don't get support. But as a developer, this isn't so much of an issue because I can debug problems myself with the help of the internet.&lt;/p&gt;

&lt;p&gt;I hate anything to do with deployment, so while self hosted sounds more difficult, for me it is a lot easier. I know how to deploy a Node.js application already, so Strapi just fits right in to my tried and tested deployment steps (although I ended up throwing that all out the window and learning something new anyway 🤷‍♀️) . It also means I save $$$ again by eliminating the middle-person.&lt;/p&gt;

&lt;p&gt;Strapi also has lots of plugins (or you can create your own) which means it only comes with what you need and you can add whatever extras you want.&lt;/p&gt;

&lt;p&gt;Open Source means that anyone can contribute to the project, so it is built for the community by the community.&lt;/p&gt;

&lt;p&gt;Basically, right out of the box it had everything I needed, and I will be able to adapt it to my needs overtime.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using Strapi
&lt;/h2&gt;

&lt;p&gt;Let's walk through the steps to get a project up and running with strapi.&lt;/p&gt;

&lt;p&gt;Also I will note here that the Strapi documentation is excellent, and they have a handy &lt;a href="https://strapi.io/documentation/3.0.0-beta.x/getting-started/quick-start-tutorial.html#_1-install-strapi-and-create-a-project" rel="noopener noreferrer"&gt;tutorial&lt;/a&gt; for installation and creating your first project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Set up
&lt;/h2&gt;

&lt;p&gt;Installation using yarn:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

yarn create strapi-app my-project


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Or npm:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

npm create-strapi-app my-project --quickstart


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This creates a new Strapi app called &lt;em&gt;my-project&lt;/em&gt; using an interactive command line interface for you to choose your settings.&lt;/p&gt;

&lt;p&gt;(You can add a &lt;code&gt;--quickstart&lt;/code&gt; flag, which will create the project with the default settings. The default settings use an sqlite database, but I wanted to use postgres).&lt;/p&gt;

&lt;p&gt;For the manual install with postgres, choose your database name and username and use the default values for host and port. For work on your local machine, a blank password is totally fine (or at least, I haven't had any disasters yet!) and I disabled SSL connection.&lt;/p&gt;

&lt;p&gt;Going through these settings should give you something that ends up looking like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

? Choose your installation type Custom (manual settings)
? Choose your default database client postgres
? Database name: dbname
? Host: 127.0.0.1
? Port: 5432
? Username: username
? Password:
? Enable SSL connection: No


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;And just like that, your project is set up and ready to go!&lt;/p&gt;

&lt;p&gt;Use the following command to start your project:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

yarn develop


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;And then head to &lt;a href="http://localhost:1337/admin" rel="noopener noreferrer"&gt;&lt;code&gt;http://localhost:1337/admin&lt;/code&gt;&lt;/a&gt; in a web browser, and set up an admin user.&lt;/p&gt;

&lt;p&gt;Once you've done that you will be presented with a page that looks something like this:&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fq3r91l8sb8sokslumk2h.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fq3r91l8sb8sokslumk2h.png" alt="Strapi admin home page."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The first thing I did was create my tables for the database. Click on &lt;em&gt;Content Type Builder&lt;/em&gt; on the left menu bar, then &lt;em&gt;Create New Content Type&lt;/em&gt;. Create the first table:&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fub8pope6v47lq9evuj04.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fub8pope6v47lq9evuj04.png" alt="Strapi content type creation form."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then click continue. Create some fields (e.g. for a blog, &lt;em&gt;Title&lt;/em&gt; and &lt;em&gt;Content&lt;/em&gt; seem like a good starting point) then click &lt;em&gt;Save&lt;/em&gt; on the top left.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fioanlezj1afaub5yt5zi.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fioanlezj1afaub5yt5zi.png" alt="Strapi content types page."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The image above shows my blog table, with the two fields.&lt;/p&gt;

&lt;p&gt;Now, I can go to &lt;em&gt;Blogs&lt;/em&gt; under &lt;em&gt;Content Types&lt;/em&gt; in the left menu bar and create a new blog post:&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fge7cmzdx3at1kqmnrmhc.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fge7cmzdx3at1kqmnrmhc.png" alt="Strapi blog entry list."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(Notice that Strapi automatically adds &lt;em&gt;created_at&lt;/em&gt; and &lt;em&gt;updated_at&lt;/em&gt; fields for every table).&lt;/p&gt;

&lt;h2&gt;
  
  
  Usage
&lt;/h2&gt;

&lt;p&gt;Cool! We now have our headless CMS set up, complete with a database for the blog. The next step is fetching that data on the front end.&lt;/p&gt;

&lt;p&gt;First, let's test if we can actually see the data. Open a new tab in your web browser and go to &lt;a href="http://localhost:1337/blogs" rel="noopener noreferrer"&gt;&lt;code&gt;http://localhost:1337/blogs&lt;/code&gt;&lt;/a&gt; (where &lt;code&gt;blogs&lt;/code&gt; is whatever you called your table). Hmmm 🤔, something seems wrong:&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ffmasvneveebksxh0zool.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ffmasvneveebksxh0zool.png" alt="Screenshot of 403 error message."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We get an error message! That is because we haven't actually told Strapi that it is ok for outsiders to fetch data, no problem, we can fix this!&lt;/p&gt;

&lt;p&gt;Head back to your admin panel in Strapi and navigate to &lt;em&gt;Roles and Permissions&lt;/em&gt;. Click &lt;em&gt;Public&lt;/em&gt;. Allow public users to &lt;em&gt;find&lt;/em&gt; and &lt;em&gt;findone&lt;/em&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F1r2qd0854q2i6s8oel78.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F1r2qd0854q2i6s8oel78.png" alt="Strapi permissions settings."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click &lt;em&gt;Save&lt;/em&gt; in the top right, and go and refresh your other tab.&lt;/p&gt;

&lt;p&gt;Hurrah, our blog is there!&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fg0irdoo5eq3efoar8jlg.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fg0irdoo5eq3efoar8jlg.png" alt="Screenshot of successful GET request results."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This means that we can now get the blog data on the front end using fetch:&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&lt;p&gt;fetch('&lt;a href="http://mystrapi.com/some-slug/'" rel="noopener noreferrer"&gt;http://mystrapi.com/some-slug/'&lt;/a&gt;)&lt;br&gt;
    .then((response) =&amp;gt; {&lt;br&gt;
        return response;&lt;br&gt;
    });&lt;/p&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Conclusion&lt;br&gt;
&lt;/h2&gt;

&lt;p&gt;So at the moment I am pretty happy with Strapi. I'll revisit this later down the track once I've played with it a bit more. But if you are a beginner and/or want something fast and easy for creating dynamic content on your site, I would definitely recommend this solution. And if you're curious as to how mine all turned out, you can check it out &lt;a href="https://hayley.codes/blog" rel="noopener noreferrer"&gt;here&lt;/a&gt; :)&lt;/p&gt;

</description>
      <category>strapi</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
