<?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: react-stockholm</title>
    <description>The latest articles on Forem by react-stockholm (@reactstockholm).</description>
    <link>https://forem.com/reactstockholm</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%2F333514%2Fc6c501c9-a74a-4a21-aa6d-2f4d3438b8f9.png</url>
      <title>Forem: react-stockholm</title>
      <link>https://forem.com/reactstockholm</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/reactstockholm"/>
    <language>en</language>
    <item>
      <title>I updated our website to use React with Next.js and DatoCMS... here is what I learned!</title>
      <dc:creator>react-stockholm</dc:creator>
      <pubDate>Wed, 19 Feb 2020 08:03:14 +0000</pubDate>
      <link>https://forem.com/reactstockholm/i-updated-our-website-to-use-react-with-next-js-and-datocms-here-is-what-i-learned-52le</link>
      <guid>https://forem.com/reactstockholm/i-updated-our-website-to-use-react-with-next-js-and-datocms-here-is-what-i-learned-52le</guid>
      <description>&lt;p&gt;I was tasked with updating our website from the static HTML-pages we've had to something that would be easier to maintain and update. I was asked to re-do the entire site using DatoCMS and the React framework "Next.js".&lt;/p&gt;

&lt;p&gt;I was tasked with updating our website from the static HTML-pages we've had to something that would be easier to maintain and update. I was asked to re-do the entire site using &lt;strong&gt;DatoCMS&lt;/strong&gt; and the &lt;strong&gt;React framework "Next.js"&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  React with Next.js
&lt;/h2&gt;

&lt;p&gt;I have dabbled in React a couple of times, gone through a couple of courses and even though the &lt;strong&gt;"create-react-app"&lt;/strong&gt; is extremely handy... I still find it &lt;strong&gt;a bit cumbersome&lt;/strong&gt; with the setup to get it up and running. &lt;strong&gt;That was until&lt;/strong&gt; I got the tip to &lt;strong&gt;check out &lt;a href="https://nextjs.org/"&gt;Next.js&lt;/a&gt;&lt;/strong&gt; which, on top of giving you a &lt;strong&gt;"Zero Setup"-setup&lt;/strong&gt;, gives you &lt;strong&gt;server-side-rendered pages&lt;/strong&gt; and a whole lot more.&lt;/p&gt;

&lt;h2&gt;
  
  
  "Zero Setup"-Setup
&lt;/h2&gt;

&lt;p&gt;If you have some experience at all with React, getting started with Next.js is a breeze! You'll find their &lt;strong&gt;&lt;a href="https://nextjs.org/learn/"&gt;"Getting started" tutorial here.&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Going through the Next.js tutorial&lt;/strong&gt; you will quickly realise that &lt;strong&gt;not much is different&lt;/strong&gt; form the plain old &lt;strong&gt;React&lt;/strong&gt; we've come to love, &lt;strong&gt;apart from some imports&lt;/strong&gt; to use Next's own components. It &lt;strong&gt;definitely easier&lt;/strong&gt; to get going and you &lt;strong&gt;get some great things like server-side-rendering of your pages for free&lt;/strong&gt;. &lt;/p&gt;

&lt;h2&gt;
  
  
  What do we want? Deployment! When do we want it? NOW!
&lt;/h2&gt;

&lt;p&gt;Server-side rendering is great and all... but &lt;strong&gt;what I personally LOVE&lt;/strong&gt; about using &lt;strong&gt;Next.js&lt;/strong&gt; if how easy it is to deploy your entire React-site to their hosting service &lt;strong&gt;Zeit&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/l3V0tsH8p70c29ZSw/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/l3V0tsH8p70c29ZSw/giphy.gif" alt="" width="500" height="338"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Deploying with Next.js is almost absurdly easy, is so easy I just did it by accident right &lt;strong&gt;now&lt;/strong&gt;... For real! &lt;strong&gt;Just type the word "now"&lt;/strong&gt;, sit back and watch the &lt;strong&gt;magic&lt;/strong&gt; unfold before your eyes! &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--j0Xy7fyz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://www.datocms-assets.com/15879/1574788397-untitled-1.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--j0Xy7fyz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://www.datocms-assets.com/15879/1574788397-untitled-1.gif" alt="" width="800" height="294"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Remembering commands can be tough... here you can copy my code:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
&lt;code&gt;now&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  That's literally it!
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/LpLd2NGvpaiys/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/LpLd2NGvpaiys/giphy.gif" alt="" width="400" height="300"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  So why did we switch over to React with Next.js?
&lt;/h2&gt;

&lt;p&gt;Our website has up until now been static HTML pages and &lt;strong&gt;we needed a faster and easier way to quickly make changes and updates&lt;/strong&gt;. First of all, we needed something modular to quickly add new content to our site, this was covered by &lt;strong&gt;React&lt;/strong&gt;, then we needed some way to easily and quickly update the content... we needed a &lt;strong&gt;CMS&lt;/strong&gt;! So which one did we go for? &lt;strong&gt;We love Dango&lt;/strong&gt; and use it a lot, therefore it has come naturally to use &lt;strong&gt;DjangoCMS&lt;/strong&gt;. But fot this project we opted for something else... we went with &lt;strong&gt;DatoCMS&lt;/strong&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  DATO CMS
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;So what is DatoCMS really?&lt;/strong&gt; On their website they claim themselves to be &lt;strong&gt;"The API-based CMS your editors will love"&lt;/strong&gt;... which actually seems pretty much like a great description of what it is.&lt;/p&gt;

&lt;p&gt;With Dato you &lt;strong&gt;define models&lt;/strong&gt; to use with their &lt;strong&gt;web based GUI&lt;/strong&gt;, you &lt;strong&gt;populate your models with data&lt;/strong&gt; and then you &lt;strong&gt;access the data&lt;/strong&gt; though &lt;strong&gt;their API&lt;/strong&gt; using &lt;strong&gt;GraphQL&lt;/strong&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  GraphQL... You want PK´s with that? 🍟
&lt;/h2&gt;

&lt;p&gt;We've all used &lt;strong&gt;REST-API's&lt;/strong&gt; but what's the deal with &lt;strong&gt;GraphQL&lt;/strong&gt;?&lt;/p&gt;

&lt;p&gt;I'we heard about GraphQL several times and I had understood that it gives more flexibility over queries. So it was time to put it to the test! &lt;strong&gt;What I hadn't realised&lt;/strong&gt; with &lt;strong&gt;GraphQL&lt;/strong&gt; was the fact that you now can use &lt;strong&gt;one single API-Endpoint&lt;/strong&gt; for &lt;strong&gt;several completely different queries&lt;/strong&gt;. This in combination with the fact that you &lt;strong&gt;"Custom Order"&lt;/strong&gt; what results you want and how you want it.&lt;/p&gt;

&lt;p&gt;So instead of getting the result of some specific API-endpoint which might return way more data than we actually need, you just declare what results you actually want and care about.&lt;/p&gt;

&lt;p&gt;For example we want to &lt;strong&gt;display the logotypes of the technologies we use at Will &amp;amp; Skill&lt;/strong&gt;. So with &lt;strong&gt;DatoCMS&lt;/strong&gt; we define a &lt;strong&gt;model&lt;/strong&gt; called &lt;strong&gt;Technology&lt;/strong&gt;. It has a &lt;strong&gt;name&lt;/strong&gt;, an image-field called &lt;strong&gt;logotype&lt;/strong&gt; and an &lt;strong&gt;ID&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MCg7rsX7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://www.datocms-assets.com/15879/1574788447-screenshot-2018-10-29-at-11-06-02.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MCg7rsX7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://www.datocms-assets.com/15879/1574788447-screenshot-2018-10-29-at-11-06-02.png" alt="" width="800" height="176"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So &lt;strong&gt;what might a GraphQL request look like&lt;/strong&gt; to get a &lt;strong&gt;list of all the technologies&lt;/strong&gt; we have entered to &lt;strong&gt;DatoCMS&lt;/strong&gt;?&lt;/p&gt;

&lt;p&gt;First of all we get a list of all the technologies with their respective ID:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GraphQL Query&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We simply write out what we want:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    allTechnologys{
        id
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;API Response&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;And this is what we get back:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; "allTechnologys": [
      {
        "id": "438377",
      },
      {
        "id": "438412",
      },
      {
        "id": "438376",
      },
      {
        "id": "438427",
      },
      {
        "id": "438365",
      }
    ],
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But what if we also want the &lt;strong&gt;names&lt;/strong&gt; of the technologies? Easy, &lt;strong&gt;just add the name field to the query&lt;/strong&gt; and &lt;strong&gt;voilà&lt;/strong&gt;!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GraphQL Query&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    allTechnologys{
        id
        name
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;API Response&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; "allTechnologys": [
      {
        "id": "438377",
        "name": "React"
      },
      {
        "id": "438412",
        "name": "React Native"
      },
      {
        "id": "438376",
        "name": "Angular"
      },
      {
        "id": "438427",
        "name": "Swift"
      },
      {
        "id": "438365",
        "name": "Django"
      }
    ],
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Let's say we also want&lt;/strong&gt; to display the corresponding &lt;strong&gt;logotypes fo the technologies&lt;/strong&gt;... just &lt;strong&gt;add the logotype field&lt;/strong&gt; and the &lt;strong&gt;parameters you want&lt;/strong&gt; (in this case we are just interested in the url of the logotype)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GraphQL Query&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    allTechnologys{
        id
        name
        logotype{
            url
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;API Response&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"allTechnologys": [
      {
        "id": "438377",
        "name": "React",
        "logotype": {
          "url": "https://www.datocms-assets.com/7863/1540395724-logoreactredux.png"
        }
      },
      {
        "id": "438412",
        "name": "React Native",
        "logotype": {
          "url": "https://www.datocms-assets.com/7863/1540394206-logoreactnative.png"
        }
      },
      {
        "id": "438376",
        "name": "Angular",
        "logotype": {
          "url": "https://www.datocms-assets.com/7863/1540394191-logoangular.png"
        }
      },
      {
        "id": "438427",
        "name": "Swift",
        "logotype": {
          "url": "https://www.datocms-assets.com/7863/1540394129-logoswift.png"
        }
      },
      {
        "id": "438365",
        "name": "Django",
        "logotype": {
          "url": "https://www.datocms-assets.com/7863/1540393940-logodjango.png"
        }
      }
    ],
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, now you can go all &lt;strong&gt;Burger King™&lt;/strong&gt; up on your API calls and &lt;strong&gt;"Have it your way"&lt;/strong&gt;... SUCCESS! 🍔🍔🍔&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/26uflHoMuKMUInB5K/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/26uflHoMuKMUInB5K/giphy.gif" alt="" width="480" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Stay tuned for part 2! &lt;/p&gt;

&lt;p&gt;This post was originally posted on our Blog: &lt;a href="https://www.willandskill.se/en/i-updated-our-website-to-use-react-with-next-js-and-datocms-here-is-what-i-learne/"&gt;Will &amp;amp; Skill, A Digital Agency based in Stockholm - I updated our website using React and Next.js&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>nextjs</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Setup a Next.js project with PM2, Nginx and Yarn on Ubuntu 18.04</title>
      <dc:creator>react-stockholm</dc:creator>
      <pubDate>Mon, 10 Feb 2020 20:17:10 +0000</pubDate>
      <link>https://forem.com/reactstockholm/setup-a-next-js-project-with-pm2-nginx-and-yarn-on-ubuntu-18-04-22c9</link>
      <guid>https://forem.com/reactstockholm/setup-a-next-js-project-with-pm2-nginx-and-yarn-on-ubuntu-18-04-22c9</guid>
      <description>&lt;p&gt;So, I recently had to deploy a Next.js project to a Ubuntu-server. Quite straight forward but you might run into some quirks. &lt;/p&gt;

&lt;p&gt;We tend to deploy our projects on Now since it is super convenient but there might be instances where You need to deploy things to Your own servers. This is a short tutorial on how You can easily setup a working environment in no time.&lt;/p&gt;

&lt;p&gt;We tend to deploy our projects on Now since it is super convenient but there might be instances where You need to deploy things to Your own servers. This is a short tutorial on how You can easily setup a working environment in no time.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Install Nginx&lt;/li&gt;
&lt;li&gt;Install Yarn&lt;/li&gt;
&lt;li&gt;Install PM2&lt;/li&gt;
&lt;li&gt;Use Git to fetch our Next.js project from Github&lt;/li&gt;
&lt;li&gt;Run our project with PM2 and serve a browsable version with Nginx&lt;/li&gt;
&lt;li&gt;Run PM2 automatically whenever we boot/reboot the machine&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  Install Nginx
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt install nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Install Yarn on Ubuntu
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update &amp;amp;&amp;amp; sudo apt-get install yarn
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Install PM2 globally on your machine
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn global add pm2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Fetch project repo from Github and install all the dependencies
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone github:&amp;lt;YOUR_ORGANIZATION&amp;gt;/&amp;lt;YOUR_PROJECT&amp;gt; project
cd project
yarn install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;NOTE: If You have Your latest code in a different branch you need to checkout that branch so if Your code resides in a branch named &lt;code&gt;development&lt;/code&gt; you need to run &lt;code&gt;git checkout development&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;NOTE: After &lt;code&gt;yarn install&lt;/code&gt; you have to run &lt;code&gt;yarn build&lt;/code&gt; so that You get a runnable version of the Next.js app&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Start the Next.js project with Yarn and PM2
&lt;/h3&gt;

&lt;p&gt;Our &lt;code&gt;package.json&lt;/code&gt; looks like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "name": "nextjs-example",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "dev": "node server.js",
    "build": "next build",
    "start": "next start -p 8000",
    "test": "NODE_ENV=test jest",
    "test:watch": "NODE_ENV=test jest --watch",
    "test:coverage": "NODE_ENV=test jest --coverage",
    "test:cypress": "NODE_ENV=test cypress open",
    "lint": "eslint .",
    "lint:watch": "esw . --watch --cache",
    "lint:watchAll": "esw . --watch",
    "circleci:run": "circleci local execute --job $JOB"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/willandskill/nextjs-example.git"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/willandskill/nextjs-example/issues"
  },
  "homepage": "https://github.com/willandskill/nextjs-example#readme",
  "dependencies": {
    ...
  },
  "devDependencies": {
    ...
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We have some extra stuff that You can ignore for now in our &lt;code&gt;package.json&lt;/code&gt;. The line that matters to us is &lt;code&gt;"start": "next start -p 8000"&lt;/code&gt; under &lt;code&gt;scripts&lt;/code&gt; and in order for us to run it from the command line we would run &lt;code&gt;yarn start&lt;/code&gt; but if we want PM2 to run it for us we need to run &lt;code&gt;pm2 start yarn --name "nextjs" --interpreter bash -- start&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To run our Next.js project and see if the process is kicking we need to run the commands below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pm2 start yarn --name "nextjs" --interpreter bash -- start
pm2 show nextjs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output should be something like&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;root@willandskill-example:# pm2 show nextjs
 Describing process with id 0 - name nextjs
┌───────────────────┬──────────────────────────────────┐
│ status            │ online                           │
│ name              │ nextjs                           │
│ version           │ N/A                              │
│ restarts          │ 2                                │
│ uptime            │ 93m                              │
│ script path       │ /usr/bin/yarn                    │
│ script args       │ start                            │
│ error log path    │ /root/.pm2/logs/nextjs-error.log │
│ out log path      │ /root/.pm2/logs/nextjs-out.log   │
│ pid path          │ /root/.pm2/pids/nextjs-0.pid     │
│ interpreter       │ bash                             │
│ interpreter args  │ N/A                              │
│ script id         │ 0                                │
│ exec cwd          │ /root/project                    │
│ exec mode         │ fork_mode                        │
│ node.js version   │ N/A                              │
│ node env          │ N/A                              │
│ watch &amp;amp; reload    │ ✘                                │
│ unstable restarts │ 0                                │
│ created at        │ 2019-03-13T15:02:40.278Z         │
└───────────────────┴──────────────────────────────────┘
 Add your own code metrics: http://bit.ly/code-metrics
 Use `pm2 logs next [--lines 1000]` to display logs
 Use `pm2 env 0` to display environement variables
 Use `pm2 monit` to monitor CPU and Memory usage next
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If You want to monitor what is happening in real time, You can run the command &lt;code&gt;pm2 monit&lt;/code&gt;. This command is quite handy if You want to see the logs&lt;br&gt;
generated in real time or see how Your hardware resources is utilized in normal/heavy traffic.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  How You deploy a new version
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git pull
yarn install
yarn build
pm2 restart nextjs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Setting up a basic Nginx config file
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# /etc/nginx/sites-available/nextjs-example.willandskill.eu

server {
    server_name nextjs-example.willandskill.eu;
    access_log /opt/nextjs/logs/access.log;
    error_log /opt/nextjs/logs/error.log error;

    location /_next/ {
        alias /opt/nextjs/project/.next/;
        expires 30d;
        access_log on;
    }

    location / {
        # reverse proxy for next server
        proxy_pass http://localhost:8000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;

        # we need to remove this 404 handling
        # because next's _next folder and own handling
        # try_files $uri $uri/ =404;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The important line in this Nginx config file is to map the traffic to &lt;code&gt;http://localhost:8000&lt;/code&gt; with the line &lt;code&gt;proxy_pass http://localhost:8000;&lt;/code&gt; under the &lt;code&gt;location /&lt;/code&gt; block.&lt;/p&gt;

&lt;h3&gt;
  
  
  If you want PM2 to start on startup
&lt;/h3&gt;



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

&lt;/div&gt;



&lt;p&gt;You can also run the command below to freeze the processes You want to run on startup&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;This article was originally posted on &lt;a href="https://www.willandskill.se/en/setup-a-next-js-project-with-pm2-nginx-and-yarn-on-ubuntu-18-04/"&gt;Will &amp;amp; Skill Blog - Setup a Next.js project with PM2, Nginx and Yarn on Ubuntu 18.04&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>nextjs</category>
      <category>pm2</category>
    </item>
  </channel>
</rss>
