<?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>DEV Community: Bryce</title>
    <description>The latest articles on DEV Community by Bryce (@brycev).</description>
    <link>https://dev.to/brycev</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%2F339821%2F3cf07686-60a1-4660-a641-9613cd2bbda5.jpeg</url>
      <title>DEV Community: Bryce</title>
      <link>https://dev.to/brycev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/brycev"/>
    <language>en</language>
    <item>
      <title>Flipping keys/values in SQL JSON</title>
      <dc:creator>Bryce</dc:creator>
      <pubDate>Thu, 13 Jul 2023 03:41:46 +0000</pubDate>
      <link>https://dev.to/brycev/flipping-keysvalues-in-sql-json-280g</link>
      <guid>https://dev.to/brycev/flipping-keysvalues-in-sql-json-280g</guid>
      <description>&lt;p&gt;Have you ever come across SQL JSON that was injected in the improper order? Something along the lines of: &lt;code&gt;{"0": "numDogs", "3": "numCats"}&lt;/code&gt; when you wanted &lt;code&gt;{"numDogs": "0", "numCats": "3"}&lt;/code&gt;? Not only is it hard to make sense of your data (How would you sum up all the total numDogs across all the rows?) it is critically dangerous for the collision of keys. If you have a couple of rows you could manually UPDATE/replace the individual fields but this is still tricky if you have more then a couple rows. &lt;/p&gt;

&lt;p&gt;I was throwing around this problem in my head and, utilizing some temp tables and the JSON cmds introduced in  5.7.8, came up with a series of SQL queries that could be a solution. They can help make the JSON's key:value =&amp;gt; value:key (or in other words your new key:value). &lt;strong&gt;Note: this only works if your values are scalar (not array/object/etc because those arent valid keys).&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;#If you want to run multiple times you have to uncomment these to drop tables. Otherwise the tables are dropped when session ends
#DROP TEMPORARY TABLE tab;
#DROP TEMPORARY TABLE tmp1;

#Create a table to separate the keys and values
#REPLACE "mytable" and "json_data" and "id" with your table/column/primary key names
CREATE TEMPORARY TABLE tab
SELECT id, mykeys, myvalues
FROM (
SELECT *,
CASE WHEN JSON_VALID(json_data) THEN JSON_KEYS(json_data) ELSE null END AS mykeys,
CASE WHEN JSON_VALID(json_data) THEN JSON_EXTRACT(JSON_UNQUOTE(json_data), "$.*") ELSE null END AS myvalues
FROM mytable
WHERE json_data!="" and json_data!="null" and json_data is not null
) mytable;

#Create and fill a table that we are just going to use as index values
#Might be a clever way to add a sequence of values to a table but this is the way I did it...
#Just verify you insert more then the number of keys in the json you are "fixing". IE my example had 2 for numDogs and numCats
create temporary table tmp1 (id tinyint unsigned not null primary key);  
insert into tmp1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),(13),(14),(15),(16),(17),(18),(19),(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),(30);  

#REPLACE "mytable" and "id" with your table/primary key designations
UPDATE mytable jTable,
  (
select myresultstable.id, JSON_OBJECTAGG(col2,col1) as JSONresult from
(
select
tab.id,
JSON_UNQUOTE(json_extract(tab.mykeys, concat('$[', tmp1.id, ']'))) as col1,
JSON_UNQUOTE(json_extract(tab.myvalues, concat('$[', tmp1.id, ']'))) as col2
FROM tmp1
join tab
) myresultstable
WHERE myresultstable.col1 is not null and myresultstable.col2 is not null
group by myresultstable.id
  ) t2
SET jTable.json_data=JSONresult
WHERE t2.id = jTable.id;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I only ask you test and verify with your own environment before running these test queries because I am not a DBA (clearly) and this will overwrite your data 🖖&lt;/p&gt;

</description>
      <category>mysql</category>
      <category>json</category>
      <category>key</category>
      <category>value</category>
    </item>
    <item>
      <title>*ERN Full Stack Creation with Bash</title>
      <dc:creator>Bryce</dc:creator>
      <pubDate>Sat, 22 Feb 2020 23:42:59 +0000</pubDate>
      <link>https://dev.to/brycev/ern-full-stack-creation-with-bash-46bh</link>
      <guid>https://dev.to/brycev/ern-full-stack-creation-with-bash-46bh</guid>
      <description>&lt;p&gt;Project structure is something every web developer has thought about at some point. Should I separate my front-end and back-end code into different repositories? If I dont, what is the perfect folder hierarchy that will benefit the way I develop and keep the two sides completely modular? &lt;/p&gt;

&lt;p&gt;This was certainly a question that I thought about after my umpteenth web application project. Being primarily a front-end developer, I have always heard that separating the back-end into its own repository was the best thing to do. However, after spending just a minute or two on google, it appeared that this architecture is not always foolproof. Like everything regarding development, there are pros and cons to both approaches. &lt;/p&gt;

&lt;p&gt;If you have a team of developers devoted to each side of the stack, then keeping the code apart obviously makes a lot of sense. The teams will be building code at different rates and debugging problem gets much simpler. If the back-end is getting used for multiple projects, that is another good reason to have it completely isolated. &lt;/p&gt;

&lt;p&gt;However, this is not the case I have found most of the time. There are a lot of independent developers out there: student, hobbyist, or even freelancers. I think a lot of people in the community fall into this category. Besides, in all of my technical internships, production level code isn't even written with this clear level of division. A lot of developers help with both sides and have both code bases installed on their machines. This is a lot of unnecessary overhead managing multiple repositories for testing and deploying small projects.&lt;/p&gt;

&lt;p&gt;So it got me thinking. How could I organize my own personal projects that could start as a single repo but also provide the best possible folder structure if I needed to separate it in the future? Then for more fun...could I simplify the project set up enough to automate the process?&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Just a few points up front: This article covers creating a bare-ish bones full stack project in the *ERN stack (&amp;lt;pick a DB&amp;gt;, Express, React, and Node). It also covers managing the front-end/back-end in the same repository. The process uses the most popular OS shell, bash, to help automate the process (As a Windows developer, I highly recommend using Git Bash). A lot of the tools/techniques might be applicable to other web project management regardless of the tech stack, but if you just want to see the finished bash script I will add it at the bottom of the page.  &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here were my two main objectives:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Keep the front-end and the back-end in the same repo, but have their dependency management completely isolated. I wanted the folder structure to look something like this:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;project name&amp;gt;
│   .git
│   package.json  
│   ...    
└───server
│   │   package.json
│   │   .gitignore
│   │   ...
│   └───client
│       │   package.json
│       │   .gitignore
│       │   ...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Automate the full stack project creation using a single command via bash&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  #1 Install the necessary CLI tools
&lt;/h1&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Like a lot of these steps, there is some personal preference. Feel free to pick and choose how you want the script to run. If you dont want to install a cli tool, you will just have to remove those lines from the script we will cover in the later steps. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Part of project will set up git version control. If you dont have it, you can &lt;a href="https://git-scm.com/book/en/v2/Getting-Started-Installing-Git"&gt;install it here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We will use node and npm, so if you do not yet have these tools you can &lt;a href="https://nodejs.org/en/download/"&gt;download them here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The only third-party cli tool I was forced pollute my global npm dependencies with was "json". &lt;a href="https://www.npmjs.com/package/json"&gt;Found on npm here&lt;/a&gt;. It helps edit us the .bashrc file quickly and easily without constantly using insane regex. Mac/Unix users potentially have native command alternatives but I was on a Windows and opted for this for simplicity. I would love to discuss a more supported alternative for this in the future.&lt;/p&gt;

&lt;h1&gt;
  
  
  #2 Create a bash function
&lt;/h1&gt;

&lt;p&gt;You know those commands that you typically use in your terminal like: &lt;code&gt;rm, cd, cp, tail&lt;/code&gt;, etc? Did you know you can actually create your own commands? The most common way of doing this is by putting aliases in your .bashrc file. This file checks for updates when you run your terminal. For example a simple alias like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;alias &lt;/span&gt;&lt;span class="nv"&gt;ll&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"ls -al"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;creates an &lt;code&gt;ll&lt;/code&gt; command that you can run from any directory and executes the commands in the parentheses. Be aware &lt;strong&gt;every time you edit the .bashrc you need to reboot the terminal or run:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;source&lt;/span&gt; ~/.bashrc
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;to update the current terminal session settings. &lt;/p&gt;

&lt;p&gt;But a single command doesn't help us very much for setting up a full stack project template. We need a batch of commands. Almost like a bash script file but more convenient. That's where bash functions stored in our .bashrc come in. Similar to most programming languages, you can create a single bash function that will run a series of statements when it is called. &lt;/p&gt;

&lt;p&gt;We will create a bash function for automating our project creation and review how it works in chunks. First find your .bashrc file (usually in your home directory) and open it in your favorite text editor.&lt;/p&gt;

&lt;h1&gt;
  
  
  #3 Creating the boiler plate folders
&lt;/h1&gt;

&lt;p&gt;Put this into your .bashrc:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#Params: &amp;lt;proj name&amp;gt;&lt;/span&gt;
newreact&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
   &lt;span class="c"&gt;#Create front-end &amp;amp; back-end boilerplate&lt;/span&gt;
   &lt;span class="nb"&gt;mkdir&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
   &lt;span class="nb"&gt;cd&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
   npx create-react-app client
   npx express-generator server &lt;span class="nt"&gt;--no-view&lt;/span&gt; &lt;span class="nt"&gt;--git&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Because we want this function to be versatile it only expects one command, the name of the project. The root folder is made with this name. We then use the incredibly helpful front-end and back-end tools offered by react and express for filling in the majority of the project files. &lt;code&gt;npx&lt;/code&gt; is a nifty tool that will execute and fetch the latest versions of their code online. I will not get to far into dependency management here but I definitely recommend looking at the benefits of global, local, and &lt;a href="https://www.npmjs.com/package/npx"&gt;&lt;code&gt;npx&lt;/code&gt; package management&lt;/a&gt; (hint: mostly use &lt;code&gt;npx&lt;/code&gt; for tools that offer a service). &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; I make some assumptions with the text in these files later on. &lt;code&gt;npx&lt;/code&gt; might be problematic for changes later on with these files. You can update/remove the &lt;code&gt;sed&lt;/code&gt; statements from the script later or use the tool versions I currently have: create-react-app 3.4.0 and express-generator 4.16.1.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A helpful review of the included flags in this section are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;"--no-view": Removes view engine templates for &lt;code&gt;express-generator&lt;/code&gt;(we want to use react for views)&lt;/li&gt;
&lt;li&gt;"--git": &lt;code&gt;express-generator&lt;/code&gt; includes a .gitignore file for the back-end&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Front-end and back-end is implemented. Done right? Well it could be, but we can take this several steps further. &lt;/p&gt;

&lt;h1&gt;
  
  
  #4 Set up the server
&lt;/h1&gt;

&lt;p&gt;Go ahead and include this code next. It customizes the details for the back-end folder.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#Params: &amp;lt;proj name&amp;gt;&lt;/span&gt;
newreact&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
   ...
   &lt;span class="c"&gt;#Set up Server&lt;/span&gt;
   &lt;span class="nb"&gt;cd &lt;/span&gt;server &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; npm &lt;span class="nb"&gt;install
   &lt;/span&gt;json &lt;span class="nt"&gt;-I&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; package.json &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"this.name=&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;1&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;-backend&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
   json &lt;span class="nt"&gt;-I&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; package.json &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"this.version=&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;0.1.0&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
   &lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="nt"&gt;-rf&lt;/span&gt; public
   npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-D&lt;/span&gt; nodemon
   &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;public"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; .gitignore
   &lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="nt"&gt;-i&lt;/span&gt; &lt;span class="nt"&gt;-E&lt;/span&gt; &lt;span class="s2"&gt;"s/(app&lt;/span&gt;&lt;span class="se"&gt;\.&lt;/span&gt;&lt;span class="s2"&gt;use&lt;/span&gt;&lt;span class="se"&gt;\(&lt;/span&gt;&lt;span class="s2"&gt;express&lt;/span&gt;&lt;span class="se"&gt;\.&lt;/span&gt;&lt;span class="s2"&gt;static&lt;/span&gt;&lt;span class="se"&gt;\(&lt;/span&gt;&lt;span class="s2"&gt;path&lt;/span&gt;&lt;span class="se"&gt;\.&lt;/span&gt;&lt;span class="s2"&gt;join&lt;/span&gt;&lt;span class="se"&gt;\(&lt;/span&gt;&lt;span class="s2"&gt;__dirname, 'public'&lt;/span&gt;&lt;span class="se"&gt;\)\)\)&lt;/span&gt;&lt;span class="s2"&gt;;)/&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;if (process.env.NODE_ENV === 'production') {&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;  app.use(express.static(path.join(__dirname, 'public')));&lt;/span&gt;&lt;span class="se"&gt;\n\n&lt;/span&gt;&lt;span class="s2"&gt;  app.get('*', (req, res) =&amp;gt; {&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;    res.sendFile(path.join(__dirname&lt;/span&gt;&lt;span class="se"&gt;\+&lt;/span&gt;&lt;span class="s2"&gt;'&lt;/span&gt;&lt;span class="se"&gt;\/&lt;/span&gt;&lt;span class="s2"&gt;public&lt;/span&gt;&lt;span class="se"&gt;\/&lt;/span&gt;&lt;span class="s2"&gt;index.html'));&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;  });&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;}/g"&lt;/span&gt; app.js
   &lt;span class="nb"&gt;rm &lt;/span&gt;routes/index.js
   &lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="nt"&gt;-i&lt;/span&gt; &lt;span class="nt"&gt;-E&lt;/span&gt; &lt;span class="s2"&gt;"s/(var indexRouter = require&lt;/span&gt;&lt;span class="se"&gt;\(&lt;/span&gt;&lt;span class="s2"&gt;'&lt;/span&gt;&lt;span class="se"&gt;\.\/&lt;/span&gt;&lt;span class="s2"&gt;routes&lt;/span&gt;&lt;span class="se"&gt;\/&lt;/span&gt;&lt;span class="s2"&gt;index'&lt;/span&gt;&lt;span class="se"&gt;\)&lt;/span&gt;&lt;span class="s2"&gt;;)//g"&lt;/span&gt; app.js
   &lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="nt"&gt;-i&lt;/span&gt; &lt;span class="nt"&gt;-E&lt;/span&gt; &lt;span class="s2"&gt;"s/(app&lt;/span&gt;&lt;span class="se"&gt;\.&lt;/span&gt;&lt;span class="s2"&gt;use&lt;/span&gt;&lt;span class="se"&gt;\(&lt;/span&gt;&lt;span class="s2"&gt;'&lt;/span&gt;&lt;span class="se"&gt;\/&lt;/span&gt;&lt;span class="s2"&gt;', indexRouter&lt;/span&gt;&lt;span class="se"&gt;\)&lt;/span&gt;&lt;span class="s2"&gt;;)//g"&lt;/span&gt; app.js
   &lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="nt"&gt;-i&lt;/span&gt; &lt;span class="nt"&gt;-E&lt;/span&gt; &lt;span class="s2"&gt;"s/(app&lt;/span&gt;&lt;span class="se"&gt;\.&lt;/span&gt;&lt;span class="s2"&gt;use&lt;/span&gt;&lt;span class="se"&gt;\(&lt;/span&gt;&lt;span class="s2"&gt;'&lt;/span&gt;&lt;span class="se"&gt;\/&lt;/span&gt;&lt;span class="s2"&gt;users', usersRouter&lt;/span&gt;&lt;span class="se"&gt;\)&lt;/span&gt;&lt;span class="s2"&gt;;)/&lt;/span&gt;&lt;span class="se"&gt;\/\/&lt;/span&gt;&lt;span class="s2"&gt;app.use('&lt;/span&gt;&lt;span class="se"&gt;\/&lt;/span&gt;&lt;span class="s2"&gt;users', usersRouter);/g"&lt;/span&gt; app.js
   json &lt;span class="nt"&gt;-I&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; package.json &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s1"&gt;'this.scripts.dev="npx nodemon"'&lt;/span&gt;
   &lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="nt"&gt;-i&lt;/span&gt; &lt;span class="s1"&gt;'s/3000/5000/g'&lt;/span&gt; ./bin/www 
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;There is a lot going on here so I will try to walk through the worst parts. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It starts by going into the folder and installing the dependencies (since express-generator doesn't do this immediately).&lt;/li&gt;
&lt;li&gt;Then it uses the global json dependency tool to help us modify our package.json file. It sets some properties like the name and the &lt;a href="https://semver.org/"&gt;semver version&lt;/a&gt;. &lt;/li&gt;
&lt;li&gt;Next, we remove the example public folder (this is injected from the front-end later).
&lt;/li&gt;
&lt;li&gt;The only module I chose to install every time is nodemon. This updates the project when node files change. &lt;/li&gt;
&lt;li&gt;Ignore the public folder when it gets injected into the back-end folder&lt;/li&gt;
&lt;li&gt;Then I modified the routes. I removed the index route and its associated file but left the user one as a quick reference. Personal preference. &lt;/li&gt;
&lt;li&gt;I had to do a large text replacement with &lt;code&gt;sed&lt;/code&gt; to change where the front-end files are served. I replaced:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;express&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;static&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;__dirname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;public&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;with this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;NODE_ENV&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;production&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;express&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;static&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;__dirname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;public&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)));&lt;/span&gt;

  &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;*&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sendFile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;__dirname&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/public/index.html&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;A run script is added for development. We installed nodemon but &lt;code&gt;npx&lt;/code&gt; will check your local project before finding the latest version. It will run slightly faster when it is installed and &lt;code&gt;npx&lt;/code&gt; instead of &lt;code&gt;npm&lt;/code&gt; future proofs execution for when it might be missing.&lt;/li&gt;
&lt;li&gt;The last step we do is change the port express uses for deploying. Since react also uses 3000, we want to change one of these default ports. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A helpful review of the included flags in this section are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;"-I": In place editing for &lt;code&gt;json&lt;/code&gt;. The file is saved with new changes&lt;/li&gt;
&lt;li&gt;"-f": Path to file for &lt;code&gt;json&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;"-e": Indicates JS expression in context of the object for &lt;code&gt;json&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;"-e": Enable back escape characters for &lt;code&gt;echo&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;"-E": Extended regular expressions for &lt;code&gt;sed&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;"-i": In place editing for &lt;code&gt;sed&lt;/code&gt;. The file is saved with new changes&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  #5 Set up the client
&lt;/h1&gt;

&lt;p&gt;Next is the client customization.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#Params: &amp;lt;proj name&amp;gt;&lt;/span&gt;
newreact&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
   ...
   &lt;span class="nb"&gt;cd&lt;/span&gt; &lt;span class="s2"&gt;"../client"&lt;/span&gt;
   json &lt;span class="nt"&gt;-I&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; package.json &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"this.name=&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;1&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;-frontend&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
   json &lt;span class="nt"&gt;-I&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; package.json &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"this.version=&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;0.1.0&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
   json &lt;span class="nt"&gt;-I&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; package.json &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s1"&gt;'this.proxy="http://localhost:5000"'&lt;/span&gt;
   &lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="nt"&gt;-rf&lt;/span&gt; &lt;span class="s2"&gt;".git"&lt;/span&gt;
   &lt;span class="nb"&gt;cd&lt;/span&gt; &lt;span class="s2"&gt;".."&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This does a a couple of things we did in the back-end but has two differences. The first one is adding a proxy to the package.json. This points our API calls to the back-end only during our development. This helps remove development CORS issues. Deploying in a production setting will connect differently as it will be located in the same place. We will also remove the .git folder created by create-react-app since we want our version control at our root level. &lt;/p&gt;

&lt;h1&gt;
  
  
  #6 Set up files at project root
&lt;/h1&gt;

&lt;p&gt;Here is a strong benefit for having all your code in a single place. The root level is where you can manage both sides of your application. You can create execution commands that are wrappers for the commands in the front and back-end. Only include dev-dependencies here and package.json scripts. The root is not supposed to be its own project, only a wrapper for the other two.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#Params: &amp;lt;proj name&amp;gt;&lt;/span&gt;
newreact&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
   ...
   &lt;span class="c"&gt;#Add root level package.json for dev work/deployment&lt;/span&gt;
   npm init &lt;span class="nt"&gt;-y&lt;/span&gt;
   &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"node_modules"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; .gitignore
   json &lt;span class="nt"&gt;-I&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; package.json &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s1"&gt;'this.author="&amp;lt;add your name&amp;gt;"'&lt;/span&gt;
   json &lt;span class="nt"&gt;-I&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; package.json &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"delete this.version"&lt;/span&gt;
   json &lt;span class="nt"&gt;-I&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; package.json &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"delete this.main"&lt;/span&gt;
   json &lt;span class="nt"&gt;-I&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; package.json &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"this.name=&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;1&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
   json &lt;span class="nt"&gt;-I&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; package.json &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s1"&gt;'this.main="./server/app.js"'&lt;/span&gt;
   &lt;span class="c"&gt;#json tool has an issue with -, so for now I am sed-ing after this tool&lt;/span&gt;
   json &lt;span class="nt"&gt;-I&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; package.json &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s1"&gt;'this.scripts.herokupostbuild="npm install --only=prod --prefix server &amp;amp;&amp;amp; npm install --only-prod --prefix client &amp;amp;&amp;amp; npm run build --prefix client &amp;amp;&amp;amp; rm -rf server/public &amp;amp;&amp;amp; cp -r client/build server/public"'&lt;/span&gt;
   json &lt;span class="nt"&gt;-I&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; package.json &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s1"&gt;'this.scripts.clientinstall="npm run build --prefix client &amp;amp;&amp;amp; rm -rf server/public &amp;amp;&amp;amp; cp -r client/build server/public"'&lt;/span&gt;
   &lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="nt"&gt;-i&lt;/span&gt; &lt;span class="s1"&gt;'s/herokupostbuild/heroku-postbuild/g'&lt;/span&gt; package.json
   json &lt;span class="nt"&gt;-I&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; package.json &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s1"&gt;'this.scripts.client="npm start --prefix client"'&lt;/span&gt;
   json &lt;span class="nt"&gt;-I&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; package.json &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s1"&gt;'this.scripts.server="npm start --prefix server"'&lt;/span&gt;
   json &lt;span class="nt"&gt;-I&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; package.json &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s1"&gt;'this.scripts.start="npm start --prefix server"'&lt;/span&gt;
   npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-D&lt;/span&gt; concurrently
   json &lt;span class="nt"&gt;-I&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; package.json &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s1"&gt;'this.scripts.dev="concurrently --kill-others-on-fail \"cd server &amp;amp;&amp;amp; npm run dev\" \"cd client &amp;amp;&amp;amp; npm start\""'&lt;/span&gt;
   &lt;span class="nb"&gt;mv &lt;/span&gt;package.json temp
   &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"{&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;engines&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;: {&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;node&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;: &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;node.exe &lt;span class="nt"&gt;-v&lt;/span&gt; | &lt;span class="nb"&gt;cut&lt;/span&gt; &lt;span class="nt"&gt;-c&lt;/span&gt; 2-&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;}}"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; temp
   &lt;span class="nb"&gt;cat &lt;/span&gt;temp | json &lt;span class="nt"&gt;--merge&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; package.json
   &lt;span class="nb"&gt;rm &lt;/span&gt;temp
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;First thing this does is create a root package.json for handling execution commands at the development stage. It adds a name, version, and removes the main file.&lt;/li&gt;
&lt;li&gt;Wrapper scripts for both sides of the stack

&lt;ul&gt;
&lt;li&gt;(opt) The first one is a heroku hook that runs before deployment. Installs all the dependencies and builds the react client and puts the files into the server&lt;/li&gt;
&lt;li&gt;The "clientinstall" script puts the client files into the server&lt;/li&gt;
&lt;li&gt;Several other scripts are implemented for starting up the front-end/back-end&lt;/li&gt;
&lt;li&gt;Then it installs concurrently as a dev-dependency. This is helpful for running the front-end and the back-end at the same time with the same command. The bash function also adds a command for using this tool&lt;/li&gt;
&lt;li&gt;Some deployment services need to have a node version, so the rest of the bash lines are just for adding that to the package.json. Windows users, make sure to include that "exe" suffix. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  #7 Add Git for version control
&lt;/h1&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#Params: &amp;lt;proj name&amp;gt;&lt;/span&gt;
newreact&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
   ...
   &lt;span class="c"&gt;#Git init&lt;/span&gt;
   git init
   &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'* text=auto'&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; .gitattributes
   git add &lt;span class="nb"&gt;.&lt;/span&gt;
   git commit &lt;span class="nt"&gt;-q&lt;/span&gt; &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s1"&gt;'Full stack React.js template built'&lt;/span&gt;

   &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n\n&lt;/span&gt;&lt;span class="s2"&gt;=== Full stack application &lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;1&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; created ==="&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This is your basic git set up. I change the new line conversions on check-in (again, Windows user) to help with cross platform development. &lt;/p&gt;

&lt;p&gt;Now at the end of the script, I chose to output a nice little message to the terminal indicating completion. &lt;/p&gt;

&lt;p&gt;A helpful review of the included flags in this section are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;"-q": Suppress feedback messages for &lt;code&gt;git&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;"-m": Add commit message for &lt;code&gt;git&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;"-e": Enable back escape characters for &lt;code&gt;echo&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  #8 Heroku deployment (opt)
&lt;/h1&gt;

&lt;p&gt;This section I have commented out since I dont include heroku with all my projects and besides, I think there is a maximum deployments limit. So using this part might effect your currently active project on the platform. However, if you have a deployment service like Heroku or Netlify this is a nice place to put the set up. You could always introduce another bash function parameter to indicate whether or not you want to push to a cloud platform. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note: Heroku can not deploy part of a repository. A cleaner method would be to figure out how to deploy only the server with the client prepackaged into the public folder. That is why most heroku project layouts put the client folder inside the server folder and call it a day. This might be a detriment for using this pattern, although this will still run on heroku. Experiments with git submodules could possibly solve this issue.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#Params: &amp;lt;proj name&amp;gt;&lt;/span&gt;
newreact&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
   ...
   &lt;span class="c"&gt;#Heroku&lt;/span&gt;
   &lt;span class="c"&gt;#heroku login&lt;/span&gt;
   &lt;span class="c"&gt;#heroku create "$1"&lt;/span&gt;
   &lt;span class="c"&gt;#git push heroku master&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;You can now create and run a full stack project after you reboot your terminal with these commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;newreact &amp;lt;project name&amp;gt;
npm run dev
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;So there you have it. A tool that can be utilized for quick full stack work. Is it the silver bullet for the perfect web application? Nah. You will find that this pattern is &lt;strong&gt;not even one found commonly in practice&lt;/strong&gt;; either the stack is in another repository or has the front-end folder inside the back-end folder. I personally think this is poor future proofing and with a little bit of work, we can create our projects that can easily adapt. Who knows? With a little bit of git mastery, since the commits are in different folders, maybe even the git history can be maintained if the folders are put into separate places. Are you starting to see the vision? 😃 &lt;/p&gt;

&lt;p&gt;As a web developer, this is an ongoing project of mine, and I would love to hear the community's thoughts! What are some common layouts and patterns you use for your web applications? &lt;/p&gt;




&lt;p&gt;Here is the complete bash function (make sure to edit it to personalize):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#Params: &amp;lt;proj name&amp;gt;&lt;/span&gt;
newreact&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
   &lt;span class="c"&gt;#Create front-end &amp;amp; back-end boilerplate&lt;/span&gt;
   &lt;span class="nb"&gt;mkdir&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
   &lt;span class="nb"&gt;cd&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
   npx create-react-app client
   npx express-generator server &lt;span class="nt"&gt;--no-view&lt;/span&gt; &lt;span class="nt"&gt;--git&lt;/span&gt;

   &lt;span class="c"&gt;#Set up Server&lt;/span&gt;
   &lt;span class="nb"&gt;cd &lt;/span&gt;server &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; npm &lt;span class="nb"&gt;install
   &lt;/span&gt;json &lt;span class="nt"&gt;-I&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; package.json &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"this.name=&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;1&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;-backend&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
   json &lt;span class="nt"&gt;-I&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; package.json &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"this.version=&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;0.1.0&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
   &lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="nt"&gt;-rf&lt;/span&gt; public
   npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-D&lt;/span&gt; nodemon
   &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;public"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; .gitignore
   &lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="nt"&gt;-i&lt;/span&gt; &lt;span class="nt"&gt;-E&lt;/span&gt; &lt;span class="s2"&gt;"s/(app&lt;/span&gt;&lt;span class="se"&gt;\.&lt;/span&gt;&lt;span class="s2"&gt;use&lt;/span&gt;&lt;span class="se"&gt;\(&lt;/span&gt;&lt;span class="s2"&gt;express&lt;/span&gt;&lt;span class="se"&gt;\.&lt;/span&gt;&lt;span class="s2"&gt;static&lt;/span&gt;&lt;span class="se"&gt;\(&lt;/span&gt;&lt;span class="s2"&gt;path&lt;/span&gt;&lt;span class="se"&gt;\.&lt;/span&gt;&lt;span class="s2"&gt;join&lt;/span&gt;&lt;span class="se"&gt;\(&lt;/span&gt;&lt;span class="s2"&gt;__dirname, 'public'&lt;/span&gt;&lt;span class="se"&gt;\)\)\)&lt;/span&gt;&lt;span class="s2"&gt;;)/&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;if (process.env.NODE_ENV === 'production') {&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;  app.use(express.static(path.join(__dirname, 'public')));&lt;/span&gt;&lt;span class="se"&gt;\n\n&lt;/span&gt;&lt;span class="s2"&gt;  app.get('*', (req, res) =&amp;gt; {&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;    res.sendFile(path.join(__dirname&lt;/span&gt;&lt;span class="se"&gt;\+&lt;/span&gt;&lt;span class="s2"&gt;'&lt;/span&gt;&lt;span class="se"&gt;\/&lt;/span&gt;&lt;span class="s2"&gt;public&lt;/span&gt;&lt;span class="se"&gt;\/&lt;/span&gt;&lt;span class="s2"&gt;index.html'));&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;  });&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;}/g"&lt;/span&gt; app.js
   &lt;span class="nb"&gt;rm &lt;/span&gt;routes/index.js
   &lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="nt"&gt;-i&lt;/span&gt; &lt;span class="nt"&gt;-E&lt;/span&gt; &lt;span class="s2"&gt;"s/(var indexRouter = require&lt;/span&gt;&lt;span class="se"&gt;\(&lt;/span&gt;&lt;span class="s2"&gt;'&lt;/span&gt;&lt;span class="se"&gt;\.\/&lt;/span&gt;&lt;span class="s2"&gt;routes&lt;/span&gt;&lt;span class="se"&gt;\/&lt;/span&gt;&lt;span class="s2"&gt;index'&lt;/span&gt;&lt;span class="se"&gt;\)&lt;/span&gt;&lt;span class="s2"&gt;;)//g"&lt;/span&gt; app.js
   &lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="nt"&gt;-i&lt;/span&gt; &lt;span class="nt"&gt;-E&lt;/span&gt; &lt;span class="s2"&gt;"s/(app&lt;/span&gt;&lt;span class="se"&gt;\.&lt;/span&gt;&lt;span class="s2"&gt;use&lt;/span&gt;&lt;span class="se"&gt;\(&lt;/span&gt;&lt;span class="s2"&gt;'&lt;/span&gt;&lt;span class="se"&gt;\/&lt;/span&gt;&lt;span class="s2"&gt;', indexRouter&lt;/span&gt;&lt;span class="se"&gt;\)&lt;/span&gt;&lt;span class="s2"&gt;;)//g"&lt;/span&gt; app.js
   &lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="nt"&gt;-i&lt;/span&gt; &lt;span class="nt"&gt;-E&lt;/span&gt; &lt;span class="s2"&gt;"s/(app&lt;/span&gt;&lt;span class="se"&gt;\.&lt;/span&gt;&lt;span class="s2"&gt;use&lt;/span&gt;&lt;span class="se"&gt;\(&lt;/span&gt;&lt;span class="s2"&gt;'&lt;/span&gt;&lt;span class="se"&gt;\/&lt;/span&gt;&lt;span class="s2"&gt;users', usersRouter&lt;/span&gt;&lt;span class="se"&gt;\)&lt;/span&gt;&lt;span class="s2"&gt;;)/&lt;/span&gt;&lt;span class="se"&gt;\/\/&lt;/span&gt;&lt;span class="s2"&gt;app.use('&lt;/span&gt;&lt;span class="se"&gt;\/&lt;/span&gt;&lt;span class="s2"&gt;users', usersRouter);/g"&lt;/span&gt; app.js
   json &lt;span class="nt"&gt;-I&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; package.json &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s1"&gt;'this.scripts.dev="npx nodemon"'&lt;/span&gt;
   &lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="nt"&gt;-i&lt;/span&gt; &lt;span class="s1"&gt;'s/3000/5000/g'&lt;/span&gt; ./bin/www 

   &lt;span class="c"&gt;#Set up Client&lt;/span&gt;
   &lt;span class="nb"&gt;cd&lt;/span&gt; &lt;span class="s2"&gt;"../client"&lt;/span&gt;
   json &lt;span class="nt"&gt;-I&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; package.json &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"this.name=&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;1&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;-frontend&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
   json &lt;span class="nt"&gt;-I&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; package.json &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"this.version=&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;0.1.0&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
   json &lt;span class="nt"&gt;-I&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; package.json &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s1"&gt;'this.proxy="http://localhost:5000"'&lt;/span&gt;
   &lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="nt"&gt;-rf&lt;/span&gt; &lt;span class="s2"&gt;".git"&lt;/span&gt;
   &lt;span class="nb"&gt;cd&lt;/span&gt; &lt;span class="s2"&gt;".."&lt;/span&gt;

   &lt;span class="c"&gt;#Add root level package.json for dev work/deployment&lt;/span&gt;
   npm init &lt;span class="nt"&gt;-y&lt;/span&gt;
   &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"node_modules"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; .gitignore
   json &lt;span class="nt"&gt;-I&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; package.json &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s1"&gt;'this.author="Bryce Vonilten"'&lt;/span&gt;
   json &lt;span class="nt"&gt;-I&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; package.json &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"delete this.version"&lt;/span&gt;
   json &lt;span class="nt"&gt;-I&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; package.json &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"delete this.main"&lt;/span&gt;
   json &lt;span class="nt"&gt;-I&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; package.json &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"this.name=&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;1&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
   json &lt;span class="nt"&gt;-I&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; package.json &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s1"&gt;'this.main="./server/app.js"'&lt;/span&gt;
   &lt;span class="c"&gt;#json tool has an issue with -, so for now I am sed-ing after this tool&lt;/span&gt;
   json &lt;span class="nt"&gt;-I&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; package.json &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s1"&gt;'this.scripts.herokupostbuild="npm install --only=prod --prefix server &amp;amp;&amp;amp; npm install --only-prod --prefix client &amp;amp;&amp;amp; npm run build --prefix client &amp;amp;&amp;amp; rm -rf server/public &amp;amp;&amp;amp; cp -r client/build server/public"'&lt;/span&gt;
   json &lt;span class="nt"&gt;-I&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; package.json &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s1"&gt;'this.scripts.clientinstall="npm run build --prefix client &amp;amp;&amp;amp; rm -rf server/public &amp;amp;&amp;amp; cp -r client/build server/public"'&lt;/span&gt;
   &lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="nt"&gt;-i&lt;/span&gt; &lt;span class="s1"&gt;'s/herokupostbuild/heroku-postbuild/g'&lt;/span&gt; package.json
   json &lt;span class="nt"&gt;-I&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; package.json &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s1"&gt;'this.scripts.client="npm start --prefix client"'&lt;/span&gt;
   json &lt;span class="nt"&gt;-I&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; package.json &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s1"&gt;'this.scripts.server="npm start --prefix server"'&lt;/span&gt;
   json &lt;span class="nt"&gt;-I&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; package.json &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s1"&gt;'this.scripts.start="npm start --prefix server"'&lt;/span&gt;
   npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-D&lt;/span&gt; concurrently
   json &lt;span class="nt"&gt;-I&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; package.json &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s1"&gt;'this.scripts.dev="concurrently --kill-others-on-fail \"cd server &amp;amp;&amp;amp; npm run dev\" \"cd client &amp;amp;&amp;amp; npm start\""'&lt;/span&gt;
   &lt;span class="nb"&gt;mv &lt;/span&gt;package.json temp
   &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"{&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;engines&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;: {&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;node&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;: &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;node.exe &lt;span class="nt"&gt;-v&lt;/span&gt; | &lt;span class="nb"&gt;cut&lt;/span&gt; &lt;span class="nt"&gt;-c&lt;/span&gt; 2-&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;}}"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; temp
   &lt;span class="nb"&gt;cat &lt;/span&gt;temp | json &lt;span class="nt"&gt;--merge&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; package.json
   &lt;span class="nb"&gt;rm &lt;/span&gt;temp

   &lt;span class="c"&gt;#Git init&lt;/span&gt;
   git init
   &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'* text=auto'&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; .gitattributes
   git add &lt;span class="nb"&gt;.&lt;/span&gt;
   git commit &lt;span class="nt"&gt;-q&lt;/span&gt; &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s1"&gt;'Full stack React.js template built'&lt;/span&gt;

   &lt;span class="c"&gt;#Heroku&lt;/span&gt;
   &lt;span class="c"&gt;#heroku login&lt;/span&gt;
   &lt;span class="c"&gt;#heroku create "$1"&lt;/span&gt;
   &lt;span class="c"&gt;#git push heroku master&lt;/span&gt;

   &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n\n&lt;/span&gt;&lt;span class="s2"&gt;=== Full stack application &lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;1&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; created ==="&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



</description>
      <category>bash</category>
      <category>react</category>
      <category>fullstack</category>
      <category>automation</category>
    </item>
  </channel>
</rss>
