<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>express Archives | Clever Cloud</title>
	<atom:link href="https://stagingv6.cleverapps.io/blog/tag/express/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>From Code to Product</description>
	<lastBuildDate>Fri, 13 Oct 2017 17:15:00 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://staging-cc-assetsv6.cellar-c2.services.clever-cloud.com/uploads/2023/03/cropped-cropped-favicon-32x32.png</url>
	<title>express Archives | Clever Cloud</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>One Framework a Day keeps the Boredom Away: Express</title>
		<link>https://stagingv6.cleverapps.io/blog/features/2017/10/13/1fdba-express/</link>
		
		<dc:creator><![CDATA[Laurent Doguin]]></dc:creator>
		<pubDate>Fri, 13 Oct 2017 17:15:00 +0000</pubDate>
				<category><![CDATA[Features]]></category>
		<category><![CDATA[1fdba]]></category>
		<category><![CDATA[express]]></category>
		<category><![CDATA[mongodb]]></category>
		<category><![CDATA[Nodejs]]></category>
		<category><![CDATA[react]]></category>
		<guid isPermaLink="false">https://www2.cleverapps.io/wp/blog/technology/2017/10/13/1fdba-express/</guid>

					<description><![CDATA[<p><img width="1400" height="540" src="https://staging-cc-assetsv6.cellar-c2.services.clever-cloud.com/uploads/2021/08/1fdba-express-1.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="" decoding="async" fetchpriority="high" srcset="https://staging-cc-assetsv6.cellar-c2.services.clever-cloud.com/uploads/2021/08/1fdba-express-1.png 1400w, https://staging-cc-assetsv6.cellar-c2.services.clever-cloud.com/uploads/2021/08/1fdba-express-1-300x116.png 300w, https://staging-cc-assetsv6.cellar-c2.services.clever-cloud.com/uploads/2021/08/1fdba-express-1-1024x395.png 1024w, https://staging-cc-assetsv6.cellar-c2.services.clever-cloud.com/uploads/2021/08/1fdba-express-1-768x296.png 768w, https://staging-cc-assetsv6.cellar-c2.services.clever-cloud.com/uploads/2021/08/1fdba-express-1-1368x528.png 1368w" sizes="(max-width: 1400px) 100vw, 1400px" /></p><p>Welcome to this new edition of <a href="/blog/features/2017/10/09/1fdba-step0/">One Framework a Day keeps the Boredom Away</a>. In this series I will show you how to deploy a particular framework on Clever Cloud every day until I want to go back to boredom. Today it&#39;s about Express.</p>
<span id="more-2909"></span>

<p>In each post of this series we&#39;ll see how to deploy a particular framework on Clever Cloud. Today we are taking a look at <a href="https://expressjs.com/">Express</a>.</p>
<p>If you want to tag along, make sure you have git, a Clever Cloud account and that you have installed our CLI <a href="https://github.com/CleverCloud/clever-tools">Clever-Tools</a>.</p>
<h2 id="what-is-express">What is Express?</h2>
<blockquote>Fast, unopinionated, minimalist web framework for Node.js</blockquote>

<p>It&#39;s pretty much the default JavaScript framework for backend stuff. It&#39;s ridiculously simple to use and benefits from a great ecosystem. If you are thinking about a particular module, there&#39;s a good chance someone already wrote it. I found a project called <a href="https://realworld.io/">RealWorld</a>. They use a Medium clone as example application and have implemented it with a variety of backend and frontend frameworks. Today I will use it as an example with their <a href="https://github.com/gothinkster/node-express-realworld-example-app">Express, MondoDB backend</a> and their <a href="https://github.com/gothinkster/react-redux-realworld-example-app">React,Redux frontend</a>.</p>
<h2 id="setup">Setup</h2>
<p>Let&#39;s start by the backend. It&#39;s a Node.js application using MongoDB so I will need a Node.js application and a MongoDB add-on.</p>
<ul>
<li>Clone the backend: <code>git clone https://github.com/gothinkster/node-express-realworld-example-app</code></li>
<li>Get in the project: <code>cd node-express-realworld-example-app</code></li>
<li>Create the Node.js application: <code>clever create --type node realworld-express</code></li>
<li>Create the MongoDB addon: <code>clever addon create mongodb-addon --plan peanut realworld-mongodb</code></li>
<li>Link the database to the application: <code>clever service link-addon realworld-mongodb</code></li>
</ul>
<p>Great thing about this application is that it&#39;s already configurable with environment variable so we just have to set them up:</p>
<ul>
<li>Configure the MongoDB connection: <code>clever env set MONGODB_URI `clever env | awk  -F = &#39;/MONGODB_ADDON_URI/ { print $2}&#39;` </code></li>
<li>Set the production flag: <code>clever env set NODE_ENV production</code></li>
<li>Set the secret used by the app: <code>clever env set SECRET myVerySecretiveSecret</code></li>
<li>Add a domain name: <code>clever domain add realworldMongoExpress.cleverapps.io</code></li>
</ul>
<p>Which make your backend ready to be deployed :)</p>
<p>Moving on to the frontend.</p>
<ul>
<li>Clone the frontend: <code>git clone https://github.com/gothinkster/react-redux-realworld-example-app</code></li>
<li>Get in the project: <code>cd react-redux-realworld-example-app</code></li>
<li>Create the Node.js application: <code>clever create --type node realworld-frontend</code></li>
<li>Set the production flag: <code>clever env set NODE_ENV production</code></li>
</ul>
<p>Sadly this one requires a little tweaking to use environment variable for configuration. I have edited the file <code>src/agent.js</code> like so:</p>
<pre><code class="language-diff">- const API_ROOT = &#39;https://conduit.productionready.io/api&#39;;
+ const API_ROOT =  process.env.API_ROOT || &#39;https://conduit.productionready.io/api&#39;;
</code></pre>
<ul>
<li>Now I can configure the backend with <code>clever env set API_ROOT https://realworldMongoExpress.cleverapps.io/api</code></li>
</ul>
<p>Don&#39;t forget to commit your changes. And now you are ready to deploy :)</p>
<h2 id="deploy">Deploy</h2>
<p>Since it&#39;s a NodeJS application, the rule for deployment is simple. There has to be a <code>main</code> or <code>scripts.start</code> field in <code>package.json</code>. For the backend is ready so all you have to do is run <code>clever deploy</code>. That&#39;s it.</p>
<p>For the frontend we have a <code>scripts.start</code> but the <em>PORT</em> variable is hardcoded. So I simply removed it and commited my change:</p>
<pre><code class="language-diff">- &quot;start&quot;: &quot;cross-env PORT=4100 react-scripts start&quot;,
+ &quot;start&quot;: &quot;cross-env react-scripts start&quot;,
</code></pre>
<p>Now it&#39;s ready for deployment. Again running <code>clever deploy</code> is all you need. Run <code>clever open</code> and your Medium clone will open in your default browser.</p>
<p>Is that it? Yes if you are not expecting too much traffic. But maybe you are indeed expecting traffic. Or maybe you don&#39;t know. Both situation are fine because Clever Cloud provides automatic scaling. Let&#39;s say you want to have 2 VM for the backend. This can be configured like this:<code>clever scale --instances 2</code></p>
<p>If you are not sure about the frontend, you can setup a minimum of 2 and a maximum of 5 like this: <code>clever scale --min-instances 2 --max-instances 5</code></p>
<p>That&#39;s it. You have deployed a MongoDB/Express backend and a React/Redux frontend in production. And you are ready for high level of traffic :)</p>
]]></description>
										<content:encoded><![CDATA[<p><img width="1400" height="540" src="https://staging-cc-assetsv6.cellar-c2.services.clever-cloud.com/uploads/2021/08/1fdba-express-1.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="" decoding="async" srcset="https://staging-cc-assetsv6.cellar-c2.services.clever-cloud.com/uploads/2021/08/1fdba-express-1.png 1400w, https://staging-cc-assetsv6.cellar-c2.services.clever-cloud.com/uploads/2021/08/1fdba-express-1-300x116.png 300w, https://staging-cc-assetsv6.cellar-c2.services.clever-cloud.com/uploads/2021/08/1fdba-express-1-1024x395.png 1024w, https://staging-cc-assetsv6.cellar-c2.services.clever-cloud.com/uploads/2021/08/1fdba-express-1-768x296.png 768w, https://staging-cc-assetsv6.cellar-c2.services.clever-cloud.com/uploads/2021/08/1fdba-express-1-1368x528.png 1368w" sizes="(max-width: 1400px) 100vw, 1400px" /></p><p>Welcome to this new edition of <a href="/blog/features/2017/10/09/1fdba-step0/">One Framework a Day keeps the Boredom Away</a>. In this series I will show you how to deploy a particular framework on Clever Cloud every day until I want to go back to boredom. Today it&#39;s about Express.</p>
<span id="more-2909"></span>

<p>In each post of this series we&#39;ll see how to deploy a particular framework on Clever Cloud. Today we are taking a look at <a href="https://expressjs.com/">Express</a>.</p>
<p>If you want to tag along, make sure you have git, a Clever Cloud account and that you have installed our CLI <a href="https://github.com/CleverCloud/clever-tools">Clever-Tools</a>.</p>
<h2 id="what-is-express">What is Express?</h2>
<blockquote>Fast, unopinionated, minimalist web framework for Node.js</blockquote>

<p>It&#39;s pretty much the default JavaScript framework for backend stuff. It&#39;s ridiculously simple to use and benefits from a great ecosystem. If you are thinking about a particular module, there&#39;s a good chance someone already wrote it. I found a project called <a href="https://realworld.io/">RealWorld</a>. They use a Medium clone as example application and have implemented it with a variety of backend and frontend frameworks. Today I will use it as an example with their <a href="https://github.com/gothinkster/node-express-realworld-example-app">Express, MondoDB backend</a> and their <a href="https://github.com/gothinkster/react-redux-realworld-example-app">React,Redux frontend</a>.</p>
<h2 id="setup">Setup</h2>
<p>Let&#39;s start by the backend. It&#39;s a Node.js application using MongoDB so I will need a Node.js application and a MongoDB add-on.</p>
<ul>
<li>Clone the backend: <code>git clone https://github.com/gothinkster/node-express-realworld-example-app</code></li>
<li>Get in the project: <code>cd node-express-realworld-example-app</code></li>
<li>Create the Node.js application: <code>clever create --type node realworld-express</code></li>
<li>Create the MongoDB addon: <code>clever addon create mongodb-addon --plan peanut realworld-mongodb</code></li>
<li>Link the database to the application: <code>clever service link-addon realworld-mongodb</code></li>
</ul>
<p>Great thing about this application is that it&#39;s already configurable with environment variable so we just have to set them up:</p>
<ul>
<li>Configure the MongoDB connection: <code>clever env set MONGODB_URI `clever env | awk  -F = &#39;/MONGODB_ADDON_URI/ { print $2}&#39;` </code></li>
<li>Set the production flag: <code>clever env set NODE_ENV production</code></li>
<li>Set the secret used by the app: <code>clever env set SECRET myVerySecretiveSecret</code></li>
<li>Add a domain name: <code>clever domain add realworldMongoExpress.cleverapps.io</code></li>
</ul>
<p>Which make your backend ready to be deployed :)</p>
<p>Moving on to the frontend.</p>
<ul>
<li>Clone the frontend: <code>git clone https://github.com/gothinkster/react-redux-realworld-example-app</code></li>
<li>Get in the project: <code>cd react-redux-realworld-example-app</code></li>
<li>Create the Node.js application: <code>clever create --type node realworld-frontend</code></li>
<li>Set the production flag: <code>clever env set NODE_ENV production</code></li>
</ul>
<p>Sadly this one requires a little tweaking to use environment variable for configuration. I have edited the file <code>src/agent.js</code> like so:</p>
<pre><code class="language-diff">- const API_ROOT = &#39;https://conduit.productionready.io/api&#39;;
+ const API_ROOT =  process.env.API_ROOT || &#39;https://conduit.productionready.io/api&#39;;
</code></pre>
<ul>
<li>Now I can configure the backend with <code>clever env set API_ROOT https://realworldMongoExpress.cleverapps.io/api</code></li>
</ul>
<p>Don&#39;t forget to commit your changes. And now you are ready to deploy :)</p>
<h2 id="deploy">Deploy</h2>
<p>Since it&#39;s a NodeJS application, the rule for deployment is simple. There has to be a <code>main</code> or <code>scripts.start</code> field in <code>package.json</code>. For the backend is ready so all you have to do is run <code>clever deploy</code>. That&#39;s it.</p>
<p>For the frontend we have a <code>scripts.start</code> but the <em>PORT</em> variable is hardcoded. So I simply removed it and commited my change:</p>
<pre><code class="language-diff">- &quot;start&quot;: &quot;cross-env PORT=4100 react-scripts start&quot;,
+ &quot;start&quot;: &quot;cross-env react-scripts start&quot;,
</code></pre>
<p>Now it&#39;s ready for deployment. Again running <code>clever deploy</code> is all you need. Run <code>clever open</code> and your Medium clone will open in your default browser.</p>
<p>Is that it? Yes if you are not expecting too much traffic. But maybe you are indeed expecting traffic. Or maybe you don&#39;t know. Both situation are fine because Clever Cloud provides automatic scaling. Let&#39;s say you want to have 2 VM for the backend. This can be configured like this:<code>clever scale --instances 2</code></p>
<p>If you are not sure about the frontend, you can setup a minimum of 2 and a maximum of 5 like this: <code>clever scale --min-instances 2 --max-instances 5</code></p>
<p>That&#39;s it. You have deployed a MongoDB/Express backend and a React/Redux frontend in production. And you are ready for high level of traffic :)</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
