<?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 Matthew King on Medium]]></title>
        <description><![CDATA[Stories by Matthew King on Medium]]></description>
        <link>https://medium.com/@matthewdking?source=rss-97a1d1185dbe------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*WyNXwb1P7YRvwL_of4ytsQ.jpeg</url>
            <title>Stories by Matthew King on Medium</title>
            <link>https://medium.com/@matthewdking?source=rss-97a1d1185dbe------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 23:23:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@matthewdking/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[Create React App plus Express.js]]></title>
            <link>https://medium.com/@matthewdking/create-react-app-with-an-express-backend-468cb6a23304?source=rss-97a1d1185dbe------2</link>
            <guid isPermaLink="false">https://medium.com/p/468cb6a23304</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[express]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[node]]></category>
            <category><![CDATA[heroku]]></category>
            <dc:creator><![CDATA[Matthew King]]></dc:creator>
            <pubDate>Tue, 13 Feb 2018 20:36:41 GMT</pubDate>
            <atom:updated>2018-03-20T15:45:18.388Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><em>Offering a simple way to work with create-react-app and with an Express backend. This aims to take you from initial set up, to serving an app on Heroku 🚀 .</em></blockquote><p>This article was born out of a frustration I had when setting up my file structure. As a result, I wanted to share my experience of creating my own setup because I have found several tutorials where multiple package.json files are located in different places, which newer coders may find confusing. Whilst this may not be the ultimate setup for bigger applications, I’ve found it a more intuitive approach and thought I would share.</p><p><em>Prerequisites</em>:</p><ul><li>Experience in React (not necessary but definitely advantageous to have played with React before)</li><li>Experience with Node/Express servers</li><li>npm and node installed on your laptop</li><li>Text-editor such as atom</li><li>Heroku CLI installed</li></ul><p>Create-react-app may have its critics, but it is a great boiler plate for beginners as it removes the cognitive load for config files and allows a quick start to get stuck in with React. Install create-react-app globally.</p><pre>npm install -global create-react-app</pre><pre>npx create-react-app name-of-app</pre><pre>cd name-of-app</pre><pre>npm init</pre><pre>npm start</pre><p>You should now have a fully working React boiler plate ✨</p><p>Great! But we want to add a backend to it so we can push our app to hosting service such as Heroku.</p><p>Create a server folder. In here is where we will store everything to do with our backend.</p><pre>mkdir server &amp;&amp; cd server</pre><pre>touch index.js</pre><p>Your app structure should now look like this.</p><pre>- name-of-app<br>  - public<br>    - favicon<br>    - index.html<br>    - manifest.json<br>  - server<br>    - index.js<br>  - src<br>    - App.css<br>    - App.js<br>    - App.test.js<br>    - index.css<br>    - index.js<br>    - logo.svg<br>    - registerServiceWorker.js<br>  - .gitignore<br>  - package-lock.json<br>  - package.json<br>  - README.md</pre><p>Lets go ahead and create an express server to serve our React frontend.</p><pre>npm install --save express</pre><p>Edit your server/index.js with the following code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f23f427abb9749fa810c5b6aefbea623/href">https://medium.com/media/f23f427abb9749fa810c5b6aefbea623/href</a></iframe><p>Sweet! As you have probably spotted though we are serving a build directory. Where did that come from? Create-react-app comes with various built in scripts, one of which creates a production build for our project.</p><pre>npm run build</pre><p>Now lets edit our package.json with a couple of extra scripts.</p><pre>npm install --save-dev nodemon</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/926602e33e7e4f5c7c157935399b3741/href">https://medium.com/media/926602e33e7e4f5c7c157935399b3741/href</a></iframe><p>So now our start script will run our express server in either dev with nodemon or production with node. If you are including a database in your project you will need to include the proxy. This should be set to the same port as you have set in the index.js. This will allow you to send requests to routes not covered in react, more details <a href="https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#proxying-api-requests-in-development">here</a>. A couple of notes on this, when you are developing you will need to be running both servers, and all /api routes should be above the line where you serve your build.</p><p>We will be using Heroku to deploy our app 🚀</p><p>Build files are for production and therefore should not be pushed to Github. Files or folders can be hidden in the .gitignore file. Luckily create-react-app comes with a .gitignore that includes /build so there is no need to change anything.</p><p>The heroku-postbuild script basically tells Heroku to build our project then run our build script creating the build directory, which is then served by our server.</p><pre>heroku create name-of-app</pre><pre>git push heroku master // assuming this code is on master</pre><p>We now have a fully functioning app on Heroku 🌟</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=468cb6a23304" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>