<?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"><channel><title><![CDATA[Remin T Roy]]></title><description><![CDATA[Expense shared as a developer ]]></description><link>https://blog.remin.in</link><generator>RSS for Node</generator><lastBuildDate>Sun, 26 Apr 2026 00:11:42 GMT</lastBuildDate><atom:link href="https://blog.remin.in/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[How to deploy - AWS / VM (Simplified)]]></title><description><![CDATA[Prequests

Any Debain based linux machine E.g. Ubuntu, Amazon Linux.

A domain name (Optional but required for making connection HTTPS).

Make sure to enable HTTP and HTTPS in the firewall (for aws its called security groups).


Step 1 - installation...]]></description><link>https://blog.remin.in/how-to-deploy-aws-vm-simplified</link><guid isPermaLink="true">https://blog.remin.in/how-to-deploy-aws-vm-simplified</guid><category><![CDATA[hosting]]></category><category><![CDATA[deployment]]></category><category><![CDATA[AWS]]></category><category><![CDATA[ec2]]></category><category><![CDATA[how to host mern app]]></category><dc:creator><![CDATA[Remin T Roy]]></dc:creator><pubDate>Mon, 24 Nov 2025 15:09:46 GMT</pubDate><content:encoded><![CDATA[<h2 id="heading-prequests">Prequests</h2>
<ul>
<li><p>Any Debain based linux machine E.g. Ubuntu, Amazon Linux.</p>
</li>
<li><p>A domain name (Optional but required for making connection HTTPS).</p>
</li>
<li><p>Make sure to <strong>enable HTTP and HTTPS in the firewall</strong> (for aws its called security groups).</p>
</li>
</ul>
<h2 id="heading-step-1-installations">Step 1 - installations</h2>
<p>Before getting into any thing lets first <strong>update your system</strong>.</p>
<pre><code class="lang-bash">sudo apt update -y &amp;&amp; sudo apt upgrade -y <span class="hljs-comment"># This will update all packages installed by apt</span>
</code></pre>
<p>Next we need to <strong>install node.js</strong></p>
<pre><code class="lang-bash">curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash
</code></pre>
<pre><code class="lang-bash"><span class="hljs-built_in">source</span> ~/.bashrc
</code></pre>
<pre><code class="lang-bash">nvm install --lts
nvm use --lts
</code></pre>
<p>Verify installations by running <code>node -v</code> and <code>npm -v</code>.</p>
<p>Now you should be able to run <code>node</code> and see REPL of Node.js. Try to run some file with <code>node index.js</code></p>
<p>Now lets <strong>install PM2</strong>, a process manager used to keep Node.js running even after closing the terminal (running Node.js in background).</p>
<pre><code class="lang-bash">npm install -g pm2
</code></pre>
<p>Verify installations by running <code>pm2 -v</code></p>
<p>Now you should be able to run <code>pm2 start index.js</code>, this will create a new process in pm2.</p>
<p>Here are some commands that come in handy</p>
<ol>
<li><p><code>pm2 startup</code> make pm2 automatically start when the system turn’s on (very helpful). make sure to turn this on so that you don’t need to worry about mannually restarting every time.</p>
</li>
<li><p><code>pm2 list</code> list all processes.</p>
</li>
<li><p><code>pm2 monit</code> monitor a process.</p>
</li>
<li><p><code>pm2 save</code> save current process list.</p>
</li>
<li><p><code>pm2 logs</code> show logs of all running process.</p>
</li>
</ol>
<p>Now let’s install one more team member <strong>Nginx,</strong> a powerfull webserver and reverse proxy (Very helpful).</p>
<pre><code class="lang-bash">sudo apt install -y nginx
</code></pre>
<p>Verify installations by running <code>nginx -v</code></p>
<p>Here are some commands that come in handy</p>
<ol>
<li><p><code>sudo systemctl start nginx</code> starts nginx.</p>
</li>
<li><p><code>sudo systemctl enable nginx</code> make nginx automatically start when the system turns on. Make sure to run this. so that you don’t need to worry about mannally starting nginx every time.</p>
</li>
<li><p><code>sudo systemctl status nginx</code> view current status on nginx service.</p>
</li>
</ol>
<p>If you have a public ip address and if the firewall is enabled you should be able to see nignx welcome page while entring your public ip <code>http://&lt;your public ip&gt;</code>.</p>
<h2 id="heading-step-2-deployment">Step 2 - Deployment.</h2>
<p>before running any commands lets first understand what we are going to do.</p>
<p>We are goning to use nginx as a proxy (distributor of requests to our projects) and a static file server (for serving react).</p>
<p>We have 3 services.</p>
<ol>
<li><p>Node.js backend (running using pm2) in port 3000. for <code>/api</code></p>
</li>
<li><p>React.js admin pannel (serving bulid using pm2) in port 5173. for <code>/admin</code></p>
</li>
<li><p>React.js main website (build files serving using nginx) for requests to <code>/</code>,</p>
</li>
</ol>
<p>Nginx will listen in the port 80 (HTTP default port) and 443 (HTTPS default port). and redirect/serve requests according to the requests’ path.</p>
<p>So if :</p>
<ol>
<li><p>Request is coming to <code>/</code> then nginx will look at the reacts’ build for for main website and serve static files according to the requests.<br /> E.g.. urls <code>http://12.12.12.12/</code> or <code>https://example.com/</code> (when ever path is or starts with <code>/</code>).</p>
</li>
<li><p>Request is coming to <code>/api</code> then nginx will redirect/forward that request to Node.js listening on 3000 and running on pm2.<br /> E.g.. urls <code>http://12.12.12.12/api/</code> or <code>https://example.com/api/</code> (when ever path is or starts with <code>/api</code>).</p>
</li>
<li><p>Request is coming to <code>/admin</code> then nginx will redirect/forward that request to React serving using pm2 on port 5173.<br /> E.g.. urls <code>http://12.12.12.12/admin/</code> or <code>https://example.com/admin/</code> (when ever path is or starts with <code>/admin</code>).</p>
</li>
</ol>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1763891313761/9233dba7-ccbd-4c49-93d7-2a0a20a44191.png" alt class="image--center mx-auto" /></p>
<p>Now lets get into implimentaion</p>
<p><strong>First lets start our backend</strong>, Clone you code or just create a new js file in the server.</p>
<pre><code class="lang-bash"><span class="hljs-built_in">cd</span> /backend <span class="hljs-comment"># Open you folder with node.js code</span>
</code></pre>
<p>For now i am creating a <code>index.js</code> file in <code>/backend</code> folder</p>
<pre><code class="lang-bash">nano index.js <span class="hljs-comment"># This will create a new file and open in nano editor</span>
</code></pre>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> http = <span class="hljs-built_in">require</span>(<span class="hljs-string">'http'</span>);

<span class="hljs-keyword">const</span> hostname = <span class="hljs-string">'localhost'</span>;
<span class="hljs-keyword">const</span> port = <span class="hljs-number">3000</span>;

<span class="hljs-keyword">const</span> server = http.createServer(<span class="hljs-function">(<span class="hljs-params">req, res</span>) =&gt;</span> {
  res.statusCode = <span class="hljs-number">200</span>;
  res.setHeader(<span class="hljs-string">'Content-Type'</span>, <span class="hljs-string">'text/plain'</span>);
  res.end(<span class="hljs-string">'Hello World!\n'</span>);
});

server.listen(port, hostname, <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">`Server running at http://<span class="hljs-subst">${hostname}</span>:<span class="hljs-subst">${port}</span>/`</span>);
});
</code></pre>
<p>Use <code>ctrl + o</code> to save the changes and <code>ctrl + x</code> to exit the nano editor.</p>
<pre><code class="lang-bash">pm2 start index.js --name test-server <span class="hljs-comment"># Change index.js to you entry poient</span>
</code></pre>
<p>Ok now backend is ready. To accessing the backend directly enable <code>3000</code> port in firewall (security groups if you are in AWS) and request to your servers <strong>public ip address</strong> or if you are in same LAN with the server use its ip address.<br />E.g.. link <code>http://12.12.12.12:3000/</code></p>
<p><strong>Now lets serve React.js admin dashboard usign pm2.</strong></p>
<p>First clone the repo and get the code to the server. and open that.</p>
<pre><code class="lang-bash"><span class="hljs-built_in">cd</span> admin-page <span class="hljs-comment"># Open your admin page directory with react project</span>
</code></pre>
<pre><code class="lang-bash">npm run build <span class="hljs-comment"># Build the project and create static files</span>
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1763997135642/ef464ba4-1dee-4ccd-b527-d61e3b14d67c.png" alt class="image--center mx-auto" /></p>
<p>To serve this using PM2’s static file server</p>
<pre><code class="lang-bash">pm2 serve --name admin-pannel ./dist 5173
</code></pre>
<p>Ok now admin page is ready. To accessing the admin page directly enable <code>5173</code> port in firewall (security groups if you are in AWS) and request to your servers <strong>public ip address</strong> or if you are in same LAN with the server use its ip address.<br />E.g.. link <code>http://12.12.12.12:5173/</code></p>
<p><strong>Now lets serve main react page using Nginx</strong></p>
<blockquote>
<p>Note : You can use pm2 to serve this one also, but for learning purpouse I am serving using Nginx.</p>
</blockquote>
<p>To service someting using nginx we need to create a config file.</p>
<p>The default folder for nginx config in Ubuntu is <code>/etc/nginx/sites-available</code> and <code>/etc/nginx/sites-enabled</code></p>
<p>What we generally do is we create a config file in <code>/etc/nginx/sites-available</code> and create a soft link of that file to <code>/etc/nginx/sites-enabled</code>. what ever files/configs is on the sites-enabled folder will get exicuted by Nginx.</p>
<p>So lets create our config file for Nginx.</p>
<pre><code class="lang-bash">sudo nano /etc/nginx/sites-available/deploy <span class="hljs-comment"># here i am using depoy as file name</span>
</code></pre>
<p>insdie that file we need to add config for Nginx.</p>
<pre><code class="lang-bash">server {
   <span class="hljs-comment"># this will match all request, if you have a domain name replace _ with your domain name.</span>
   server_name _; 

    <span class="hljs-comment"># This is the folder where nginx look for you react dist folder.</span>
    <span class="hljs-comment"># Make sure to give the correct path or copy dist output to the below folder</span>
    root /var/www/my-react-app; 

    <span class="hljs-comment"># Configuring default file to serve.</span>
    index index.html; 

    <span class="hljs-comment"># this will serve static files according to url else index.html</span>
    location / {
       try_files <span class="hljs-variable">$uri</span> <span class="hljs-variable">$uri</span>/ /index.html; 
    }

    <span class="hljs-comment"># Forward all request to Node.js running on PM2 at 3000</span>
    location /api {
       proxy_pass http://localhost:3000;
       proxy_http_version 1.1;
       proxy_set_header Upgrade <span class="hljs-variable">$http_upgrade</span>;
       proxy_set_header Connection <span class="hljs-string">'upgrade'</span>;
       proxy_set_header Host <span class="hljs-variable">$host</span>;
       proxy_cache_bypass <span class="hljs-variable">$http_upgrade</span>;
    }

    <span class="hljs-comment"># Forward all request to React.js serving from PM2 at 5173</span>
    location /admin {    
       proxy_pass http://localhost:5173;
       proxy_http_version 1.1;
       proxy_set_header Upgrade <span class="hljs-variable">$http_upgrade</span>;
       proxy_set_header Connection <span class="hljs-string">'upgrade'</span>;
       proxy_set_header Host <span class="hljs-variable">$host</span>;
       proxy_cache_bypass <span class="hljs-variable">$http_upgrade</span>;
    }

    <span class="hljs-comment"># Optional: gzip compression for better performance</span>
    gzip on;
    gzip_types text/plain text/css application/javascript application/json image/svg+xml;
    gzip_min_length 256;
}
</code></pre>
<p>Use <code>ctrl + o</code> to save the changes and <code>ctrl + x</code> to exit the nano editor.</p>
<p>Now link the file to <code>sites-enabled</code> folder</p>
<pre><code class="lang-bash">sudo ln -s /etc/nginx/sites-available/deploy /etc/nginx/sites-enabled/
</code></pre>
<p>It's a good practice to remove old non used nginx configs from <code>sites-enabled</code> folder</p>
<pre><code class="lang-bash">sudo rm /etc/nginx/sites-enabled/default
</code></pre>
<p>before starting nginx test your config files for errors</p>
<pre><code class="lang-bash">sudo nginx -t
</code></pre>
<pre><code class="lang-bash">sudo systemctl restart nginx <span class="hljs-comment"># Start if not running otherwise restart nginx.</span>
</code></pre>
<p>Hurray, Now you should be able to see your deployment by opening you public ip address in you browser.</p>
<p>E.g.. link</p>
<ul>
<li><p><code>http://12.12.12.12:5173/</code> for your main react app.</p>
</li>
<li><p><code>http://12.12.12.12:5173/admin/</code> for your react admin app.</p>
</li>
<li><p><code>http://12.12.12.12:5173/api/</code> for your node.js backend.</p>
</li>
</ul>
<h2 id="heading-step-3-adding-ssl-certificates-http-to-https">Step 3 - <strong>Adding SSL certificates - HTTP to HTTPS</strong></h2>
<p><a target="_blank" href="https://letsencrypt.org/"><strong>Let’s Encrypt</strong></a> is a Certificate Authority (CA) that provides an easy way to obtain and install free <a target="_blank" href="https://www.digitalocean.com/community/tutorials/openssl-essentials-working-with-ssl-certificates-private-keys-and-csrs"><strong>TLS/SSL certificates</strong></a><strong>,</strong> thereby enabling encrypted HTTPS on web servers. It simplifies the process by providing a software client, Certbot, that attempts to automate most (if not all) of the required steps. Currently, the entire process of obtaining and installing a certificate is fully automated on both Apache and Nginx.</p>
<p>Let's install <code>certbot</code> along with its <code>nginx plugin</code></p>
<pre><code class="lang-bash">sudo apt install certbot python3-certbot-nginx
</code></pre>
<p>Certbot will find correct <code>server_name</code> directive that matches the domain name you mentioned on the command and automatically add certificates. It will update our Nginx Confing file that we have created with 443 port binding (for listening to HTTPS requests).</p>
<p>Ok lets run <code>certbot</code></p>
<pre><code class="lang-bash">sudo certbot --nginx -d your_domain_name <span class="hljs-comment"># Replace your_domain_name with your actucal domain name</span>
</code></pre>
<p>So select your choice and hit <code>ENTER</code>. The configuration will be updated, and Nginx will reload to pic up the new settings.</p>
<p>Your certificates are downloaded, installed, and loaded. Try reloading your website using <code>https://</code> and notice your browser’s security indicator. It should indicate that the site is properly secured, usually with a lock icon. If you test your server using the <a target="_blank" href="https://www.ssllabs.com/ssltest/"><strong>SSL Labs Server Test</strong></a>, <a target="_blank" href="https://www.ssllabs.com/ssltest/">it will get an <strong>A</strong> gr</a>ade.</p>
<p>Happy coding :)</p>
]]></content:encoded></item><item><title><![CDATA[Deploy React App -  Production Server]]></title><description><![CDATA[NOTE: This blog primarily focuses on Linux systems to host and deploy on servers.
In this blog

How to create a build file

How to deploy in production


If you don't know how to set up a production Linux server (AWS or Any other Debian Server) You c...]]></description><link>https://blog.remin.in/deploy-react-app-production-server</link><guid isPermaLink="true">https://blog.remin.in/deploy-react-app-production-server</guid><category><![CDATA[hosting]]></category><category><![CDATA[React]]></category><category><![CDATA[linux-server]]></category><category><![CDATA[pm2]]></category><category><![CDATA[npm]]></category><dc:creator><![CDATA[Remin T Roy]]></dc:creator><pubDate>Tue, 15 Aug 2023 08:20:33 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1716965463089/1e297faf-6d6c-419e-9836-00a899147e72.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>NOTE: This blog primarily focuses on Linux systems to host and deploy on servers.</p>
<h4 id="heading-in-this-blog">In this blog</h4>
<ul>
<li><p>How to create a build file</p>
</li>
<li><p>How to deploy in production</p>
</li>
</ul>
<p>If you don't know how to set up a production Linux server (AWS or Any other Debian Server) You can check my article <a target="_blank" href="https://blog.remin.in/hosting-mern-app-on-server-ubuntu-2204-2023">Setup your server for production</a></p>
<p>After setup, your server should have Node.js, npm, pm2, and Nginx. With that being set we can start our deploying process</p>
<h3 id="heading-1-setting-up-the-react-app">1. Setting up the React app</h3>
<h4 id="heading-why-is-creating-a-build-important">Why is creating a build important?</h4>
<p>Creating a build file is crucial in the context of React (and web development in general) for several important reasons:</p>
<p>Creating a build file is important for React projects. Here's why:</p>
<p><strong>Makes Things Fast</strong>: Build files are like streamlined versions of your code. They load quicker, which means your website loads faster for users.</p>
<p><strong>Less Waiting</strong>: With a build file, there are fewer separate requests to the server. This reduces waiting time and makes your website snappier.</p>
<p><strong>Keeps Things in Storage</strong>: Build files are more likely to be saved in a user's browser. This means when they come back to your site, things load up even quicker from their storage.</p>
<p><strong>Smart Loading</strong>: Build files can be split, so only the parts needed are loaded. This helps your site start up faster.</p>
<p><strong>Slimmed Down Code</strong>: Build files and remove extra stuff like spaces and long words. This makes files smaller and your site faster.</p>
<p><strong>Works Everywhere</strong>: Build files can turn newer code into older code that works on more browsers. This way, your site is compatible with lots of devices.</p>
<p><strong>Safe and Sound</strong>: By getting rid of certain extra things, build files make your site safer from bad guys.</p>
<p><strong>Takes Care of Everything</strong>: Build processes and handle other stuff like images and fonts, making sure everything works perfectly on your website.</p>
<blockquote>
<p>Here are some points worth noting: <strong>Optimization, Reduced Network Requests, Caching, Code Splitting, Minification, Compatibility, Security, Static Asset Management</strong></p>
</blockquote>
<p>In short, build files make your React site faster, smoother, and safer for people to use. They're like your site's supercharged version for the real world!</p>
<h4 id="heading-so-how-do-we-create-a-build">So how do we create a build?</h4>
<p>Creating a build file is relatively easy, especially when you're using tools like Create-React-App or Vite to set up your React application. These tools streamline the process and generate optimized build files for you.</p>
<p>Assuming you already created a React application. We will directly jump to the building part.</p>
<pre><code class="lang-markdown">npm run build
</code></pre>
<p>This will create an optimized build for your project.</p>
<p>The name of the build folder may vary from <code>dist</code>, <code>build</code> some other based on what you used to start your project. In my case, I used Vite to start my app.</p>
<p>Okay, I created a build file how do I make this live? Don't worry I got you</p>
<h3 id="heading-2-running-your-react-app-from-the-build">2. Running your React app from the build</h3>
<p>For serving your React app we are using <code>pm2</code> . if you are not installed <code>pm2</code> you can do it using</p>
<pre><code class="lang-markdown">sudo npm install pm2 -g
</code></pre>
<p>To run the React app from the build</p>
<pre><code class="lang-markdown"> pm2 serve /path/to/build 8000 --name react-app --spa
</code></pre>
<p>Here <code>8000</code> is the port number. Replace <code>/path/to/build</code> with an actual path to build</p>
<h3 id="heading-3-making-it-online">3. Making it online!</h3>
<p>We can use nginx to serve this online or available to the public for that you can refer to <a target="_blank" href="https://blog.remin.in/hosting-mern-app-on-server-ubuntu-2204-2023">Setup your server for production</a></p>
]]></content:encoded></item><item><title><![CDATA[Hosting MERN app on AWS Ubuntu 22.04 - 2023]]></title><description><![CDATA[This article is for beginners' guide to hosting and deploying their projects to a server or any Ubuntu 22.04 machine. Here is the whole walk through of what is going to do in this article.


Creating AWS instance

Setup by installing library and appl...]]></description><link>https://blog.remin.in/hosting-mern-app-on-server-ubuntu-2204-2023</link><guid isPermaLink="true">https://blog.remin.in/hosting-mern-app-on-server-ubuntu-2204-2023</guid><category><![CDATA[Ubuntu]]></category><category><![CDATA[server]]></category><category><![CDATA[nginx]]></category><category><![CDATA[AWS]]></category><category><![CDATA[hosting-nodejs]]></category><dc:creator><![CDATA[Remin T Roy]]></dc:creator><pubDate>Tue, 25 Jul 2023 16:20:55 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1716966190592/5f36c3da-70c3-4a2d-8ca7-55b7de23a3c7.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>This article is for beginners' guide to hosting and deploying their projects to a server or any Ubuntu 22.04 machine. Here is the whole walk through of what is going to do in this article.</p>
<hr />
<ul>
<li><p>Creating AWS instance</p>
</li>
<li><p>Setup by installing library and application</p>
<ul>
<li><p>Npm &amp; Nodejs</p>
</li>
<li><p>MongoDB</p>
</li>
<li><p>Pm2 (npm package)</p>
</li>
<li><p>Nginx</p>
</li>
<li><p>UFW (firewall)</p>
</li>
</ul>
</li>
<li><p>Starting serving</p>
<ul>
<li>Running js using pm2</li>
</ul>
</li>
<li><p>Securing server with SSL certificate</p>
</li>
</ul>
<hr />
<h4 id="heading-preparations-you-need-to-take">Preparations you need to take</h4>
<blockquote>
<p>Get a domain name for hosting.</p>
</blockquote>
<h3 id="heading-setting-up-your-linux-server-ubuntu-2204-lts">Setting up your Linux server - Ubuntu 22.04 LTS</h3>
<p>Whenever we get a server it's a good practice to update the repository and packages, If you are going to download and use new packages. In this case, we are using an apt package manager to install the necessary packages.</p>
<p>It's more like updating the whole system.</p>
<pre><code class="lang-bash">sudo apt update
</code></pre>
<pre><code class="lang-bash">sudo apt upgrade -y
</code></pre>
<p>If you are doing it for the first time this may take some time.</p>
<h3 id="heading-installing-software-and-required-packages">Installing software and required packages</h3>
<p>For hosting a NodeJS app successfully we need some packages and dependencies.</p>
<ol>
<li><h3 id="heading-installing-nodejs">Installing NodeJS</h3>
</li>
</ol>
<p>So let's start by installing <code>npm</code>. Which also comes with <code>NodeJS</code></p>
<pre><code class="lang-bash">sudo apt install npm -y
</code></pre>
<p>This will install npm with the latest version which is on the apt repository. But as of now, the day I am writing. This will be the download <code>node of version 12. x.x</code>. So this could be a problem if you try to use new features like a <code>ternary operator</code> or <code>optional chaining</code> Which is only supported on the latest versions of NodeJS.</p>
<p>To avoid any kind of problem with the NodeJS version and feature missing we need to update NodeJS and npm.</p>
<p>To update NodeJS we can use an npm package called <code>n</code>.</p>
<pre><code class="lang-bash">sudo npm install n -g
</code></pre>
<pre><code class="lang-bash">sudo n stable
</code></pre>
<p>This will update the NodeJS to the latest stable version. To check the node version use the following command</p>
<pre><code class="lang-bash">node --version
</code></pre>
<ol>
<li><h3 id="heading-installing-mongodb">Installing MongoDB</h3>
</li>
</ol>
<p>If you are using Atlas (a fully managed database cloud by MongoDB), You can skip this step. Otherwise, you need to install MongoDB locally to run your code.</p>
<p>You can refer to <a target="_blank" href="https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-ubuntu/">MongoDB's official installation doc</a> for Ubuntu 22.04. By the time you read this article, the following commands may be outdated so I would recommend checking official installation documentation.</p>
<p>Anyway here is how we install MongoDB.</p>
<p>Install dependencies for the installation of MongoDB.</p>
<pre><code class="lang-bash">sudo apt install gnupg curl
</code></pre>
<p>Enter the following command to import the MongoDB public GPG Key from <a target="_blank" href="https://pgp.mongodb.com/server-6.0.asc">https://pgp.mongodb.com/server-6.0.asc</a></p>
<pre><code class="lang-bash">curl -fsSL https://pgp.mongodb.com/server-6.0.asc | \
   sudo gpg -o /usr/share/keyrings/mongodb-server-6.0.gpg \
   --dearmor
</code></pre>
<p>Create the <code>/etc/apt/sources.list.d/mongodb-org-6.0.list</code> file for <strong>Ubuntu 22.04 (Jammy)</strong> Other version's sources list is on <a target="_blank" href="https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-ubuntu/">Official documentation</a></p>
<pre><code class="lang-bash"><span class="hljs-built_in">echo</span> <span class="hljs-string">"deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-6.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/6.0 multiverse"</span> | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
</code></pre>
<p>Enter the following command to reload the local package database</p>
<pre><code class="lang-bash">sudo apt update
</code></pre>
<p>To install the latest stable version, use the following command</p>
<pre><code class="lang-bash">sudo apt install -y mongodb-org
</code></pre>
<p>The installation is complete. so let's enable Mongodb to start the startup of the system.</p>
<pre><code class="lang-bash">sudo systemctl <span class="hljs-built_in">enable</span> mongod
</code></pre>
<p>To start MongoDB we can use</p>
<pre><code class="lang-bash">sudo systemctl start mongod
</code></pre>
<p>we can also view the status of the MongoDB service by simply typing <code>sudo systemctl status mongod</code>.</p>
<p>We successfully installed MongoDB and now we can access the MongoDB shell by typing <code>mongosh</code>.</p>
<ol>
<li><h3 id="heading-installing-pm2-npm-package">Installing PM2 (npm package)</h3>
</li>
</ol>
<p>PM2 is a process manager for Node.js applications that simplifies the process of managing and deploying Node.js applications in production environments. It is designed to keep your Node.js applications running continuously, ensuring high availability and improved performance. PM2 stands for "Production Process Manager 2."</p>
<p>PM2 is an npm package, and it's fairly easy to install.</p>
<pre><code class="lang-bash">sudo npm install pm2 -g
</code></pre>
<p>That's it PM2 is successfully installed globally.</p>
<ol>
<li><h3 id="heading-installing-nginx">Installing Nginx</h3>
</li>
</ol>
<p>NGINX is <strong>an open-source web server software that can be used for web serving, reverse proxying, caching, load balancing, media streaming, and more</strong>. And it is really fast !.</p>
<p>NGINX is designed to handle a high number of connections simultaneously, making it one of the most powerful and scalable server software options on the market</p>
<p>To install <code>nginx</code> use the following command</p>
<pre><code class="lang-bash">sudo apt install nginx
</code></pre>
<p>This will install the latest stable version of Nginx available in the apt repository.</p>
<p>As our machine is a server and we don't need to manually start nginx as a service every time we boot or reboot our system. To address this issue we can enable nginx to run on start-up using the following command.</p>
<pre><code class="lang-bash">sudo systemctl <span class="hljs-built_in">enable</span> nginx
</code></pre>
<p>To start nginx we can use</p>
<pre><code class="lang-bash">sudo systemctl start nginx
</code></pre>
<p>we can also view the status of the Nginx service by simply typing <code>sudo systemctl status nginx</code>.</p>
<ol>
<li><h3 id="heading-ufw-firewall">UFW (firewall)</h3>
</li>
</ol>
<p>UFW stands for "Uncomplicated Firewall." It is a user-friendly command-line tool used in Linux-based systems, such as Ubuntu, to manage the system's firewall settings. UFW provides a simple and easy-to-use interface for configuring and controlling firewall rules, making it accessible to both novice and experienced users.</p>
<p>NOTE: If you are using an AWS instance for hosting configuring UFW is not a necessary stop since AWS comes with its firewall called security groups. Learn more about it from their <a target="_blank" href="https://docs.aws.amazon.com/vpc/latest/userguide/security-groups.html">official documentation</a></p>
<p>To install UFW use -</p>
<pre><code class="lang-bash">sudo apt install ufw
</code></pre>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">To see available applications for adding in UFW use <code>sudo ufw app list</code>. you should see <code>Nginx Full</code>, <code>Nginx HTTP</code> and <code>Nginx HTTPS</code> is on the list.</div>
</div>

<p>now let's allow full <code>HTTP</code> and <code>HTTPS</code> access to nginx.</p>
<pre><code class="lang-bash">sudo ufw allow <span class="hljs-string">'Nginx Full'</span>
</code></pre>
<p>Use the following command to view all apps and ports managed by the firewall.</p>
<pre><code class="lang-bash">sudo ufw status
</code></pre>
<pre><code class="lang-bash">To                         Action      From
--                         ------      ----
Nginx Full                 ALLOW       Anywhere                  
OpenSSH                    ALLOW       Anywhere                  
Nginx Full (v6)            ALLOW       Anywhere (v6)             
OpenSSH (v6)               ALLOW       Anywhere (v6)
</code></pre>
<p>IMPORTANT NOTE: If you are using SSL to connect to an instance you must check <code>OpenSSH</code> is enabled in the firewall, to access your server. otherwise, you will have some real trouble accessing your server! , If <code>OpenSSH</code> is not listed in the <code>sudo ufw status</code>.</p>
<pre><code class="lang-bash">sudo ufw allow openssh
</code></pre>
<p>This will enable ssh to our server.</p>
<h3 id="heading-start-serving-your-app">Start serving your app</h3>
<p>Let's start by serving a simple <code>express</code> server.</p>
<ol>
<li>Create and open files in an editor.</li>
</ol>
<pre><code class="lang-bash"><span class="hljs-built_in">cd</span> ~
touch index.js
vim index.js
</code></pre>
<ol>
<li>wirte simple http sever in nodejs</li>
</ol>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> http = <span class="hljs-built_in">require</span>(<span class="hljs-string">'http'</span>);

<span class="hljs-keyword">const</span> hostname = <span class="hljs-string">'localhost'</span>;
<span class="hljs-keyword">const</span> port = <span class="hljs-number">3000</span>;

<span class="hljs-keyword">const</span> server = http.createServer(<span class="hljs-function">(<span class="hljs-params">req, res</span>) =&gt;</span> {
  res.statusCode = <span class="hljs-number">200</span>;
  res.setHeader(<span class="hljs-string">'Content-Type'</span>, <span class="hljs-string">'text/plain'</span>);
  res.end(<span class="hljs-string">'Hello World!\n'</span>);
});

server.listen(port, hostname, <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">`Server running at http://<span class="hljs-subst">${hostname}</span>:<span class="hljs-subst">${port}</span>/`</span>);
});
</code></pre>
<ol>
<li>Press <code>escape</code> and <code>:wq</code> to save and exit from Vim</li>
</ol>
<p>Now we can start our server using PM2</p>
<pre><code class="lang-bash">pm2 start index.js --name test-server
</code></pre>
<pre><code class="lang-bash"><span class="hljs-comment"># Your screen should looks like this</span>
[PM2] Spawning PM2 daemon with pm2_home=/home/ubuntu/.pm2
[PM2] PM2 Successfully daemonized
[PM2] Starting /home/ubuntu/index.js <span class="hljs-keyword">in</span> fork_mode (1 instance)
[PM2] Done.
┌────┬────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name           │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
├────┼────────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0  │ test-server    │ default     │ N/A     │ fork    │ 1152923  │ 0s     │ 0    │ online    │ 0%       │ 37.3mb   │ ubuntu   │ disabled │
└────┴────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
</code></pre>
<p>That's it with the pm2 side. so let's configure Nginx for accessing this on the internet. Nginx default configuration is on <code>/etc/nginx/sites-available</code> so we are going to create a file with our domain name there.</p>
<pre><code class="lang-bash">sudo vim /etc/nginx/sites-available/your_domain_name
</code></pre>
<p>Replace your <code>your_domain_name</code> with your actual domain name. This will open an editor and we can add nginx configurations here.</p>
<pre><code class="lang-nginx"><span class="hljs-section">server</span> {
   <span class="hljs-attribute">server_name</span> your_domain_name www.your_domain_name;
   <span class="hljs-attribute">location</span> / {
       <span class="hljs-attribute">proxy_pass</span> http://localhost:3000;
       <span class="hljs-attribute">proxy_http_version</span> <span class="hljs-number">1</span>.<span class="hljs-number">1</span>;
       <span class="hljs-attribute">proxy_set_header</span> Upgrade <span class="hljs-variable">$http_upgrade</span>;
       <span class="hljs-attribute">proxy_set_header</span> Connection <span class="hljs-string">'upgrade'</span>;
       <span class="hljs-attribute">proxy_set_header</span> Host <span class="hljs-variable">$host</span>;
       <span class="hljs-attribute">proxy_cache_bypass</span> <span class="hljs-variable">$http_upgrade</span>;
   }
}
</code></pre>
<p>Now save and exit the file. To save and exit use <code>escape</code> and press <code>:wqEnder</code>. The next step is to add a soft link to this file we created to <code>sites-enabled</code> folder of nginx.</p>
<pre><code class="lang-bash">sudo ln -s /etc/nginx/sites-available/your_domain_name /etc/nginx/sites-enabled
</code></pre>
<p>It's a good practice to remove old non used nginx configs from <code>sites-enabled</code> folder</p>
<pre><code class="lang-bash">sudo rm /etc/nginx/sites-enabled/default
</code></pre>
<p>Test our newly added config.</p>
<pre><code class="lang-bash">sudo nginx -t
</code></pre>
<pre><code class="lang-bash"><span class="hljs-comment"># Your screen should look like this</span>
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf <span class="hljs-built_in">test</span> is successful
</code></pre>
<p>Now let's restart nginx.</p>
<pre><code class="lang-bash">sudo systemctl restart nginx
</code></pre>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">use <code>sudo systemctl status nginx</code> to get the status of the nginx service.</div>
</div>

<h3 id="heading-check-your-browser">Check your browser!</h3>
<p>If everything is configured correctly so far, you should see "<code>Hello world</code>" in your browser by opening a new tab with your instance's public IP as your address.</p>
<p>You can just clone your project from Git Hub or edit index.js and run it in PM2 to customize the response.</p>
<p>If your project runs on a different you need to update the Nginx config to access the project from outside.</p>
<h3 id="heading-adding-ssl-certificates-http-to-https">Adding SSL certificates - HTTP to HTTPS</h3>
<p>After successfully hosting your project with Nginx now it's time to protect our website with an SSL certificate.</p>
<p><a target="_blank" href="https://letsencrypt.org/">Let’s Encrypt</a> is a Certificate Authority (CA) that provides an easy way to obtain and install free <a target="_blank" href="https://www.digitalocean.com/community/tutorials/openssl-essentials-working-with-ssl-certificates-private-keys-and-csrs">TLS/SSL certificates</a>, thereby enabling encrypted HTTPS on web servers. It simplifies the process by providing a software client, Certbot, that attempts to automate most (if not all) of the required steps. Currently, the entire process of obtaining and installing a certificate is fully automated on both Apache and Nginx.</p>
<p>This guide will walk you through the process of using Certbot to secure a free SSL certificate for Nginx on Ubuntu 20.04, and you'll also learn how to set it up for automatic renewal.</p>
<p>Let's install <code>certbot</code> along with its <code>nginx plugin</code></p>
<pre><code class="lang-bash">sudo apt install certbot python3-certbot-nginx
</code></pre>
<ul>
<li>Obtaining SSL certificate</li>
</ul>
<p>Certbot needs to be able to find the correct <code>server</code> block in your Nginx configuration for it to be able to automatically configure SSL. Specifically, it does this by looking for a <code>server_name</code> directive that matches the domain you request a certificate for. In our case its <code>your_domain_name</code>.</p>
<pre><code class="lang-bash">sudo certbot --nginx -d your_domain_name -d www.your_domain_name
</code></pre>
<p>If that’s successful, <code>certbot</code> will ask how you’d like to configure your HTTPS settings.</p>
<pre><code class="lang-markdown">OutputPlease choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
<span class="hljs-bullet">-</span> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
<span class="hljs-bullet">-</span> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel):
</code></pre>
<p>Select your choice then hit <code>ENTER</code>. The configuration will be updated, and Nginx will reload to pick up the new settings. <code>certbot</code> will wrap up with a message telling you the process was successful and where your certificates are stored:</p>
<pre><code class="lang-bash">OutputIMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/example.com/privkey.pem
   Your cert will expire on 2020-08-18. To obtain a new or tweaked
   version of this certificate <span class="hljs-keyword">in</span> the future, simply run certbot again
   with the <span class="hljs-string">"certonly"</span> option. To non-interactively renew *all* of
   your certificates, run <span class="hljs-string">"certbot renew"</span>
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let<span class="hljs-string">'s Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le</span>
</code></pre>
<p>Your certificates are downloaded, installed, and loaded. Try reloading your website using <code>https://</code> and notice your browser’s security indicator. It should indicate that the site is properly secured, usually with a lock icon. If you test your server using the <a target="_blank" href="https://www.ssllabs.com/ssltest/">SSL Labs Server Test</a>, it will get an <strong>A</strong> grade.</p>
<p>With that being set you are good to handle hosting in Ubuntu 22.04.</p>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">This article is inspired by <code>Digital Ocean's</code> NodeJS hosting documentation. For further reference, you can always refer <a target="_blank" href="https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-20-04">Digital Oceans doc</a>.</div>
</div>

<p>Hope this article helps.</p>
<p>Stay creative; Thak you : 🤍</p>
]]></content:encoded></item></channel></rss>