<?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: Phillip Ninan</title>
    <description>The latest articles on DEV Community by Phillip Ninan (@ninan_phillip).</description>
    <link>https://dev.to/ninan_phillip</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%2F457375%2Fcc433bf0-64b1-4bf5-9659-80a8496f49de.png</url>
      <title>DEV Community: Phillip Ninan</title>
      <link>https://dev.to/ninan_phillip</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ninan_phillip"/>
    <language>en</language>
    <item>
      <title>Provision an RDS Instance using the AWS CDK and Secrets</title>
      <dc:creator>Phillip Ninan</dc:creator>
      <pubDate>Wed, 11 Aug 2021 03:50:01 +0000</pubDate>
      <link>https://dev.to/ninan_phillip/provision-an-rds-instance-using-the-aws-cdk-and-secrets-88f</link>
      <guid>https://dev.to/ninan_phillip/provision-an-rds-instance-using-the-aws-cdk-and-secrets-88f</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;TLDR:&lt;/strong&gt; Checkout the complete code on &lt;a href="https://github.com/fourgates/aws-cdk-rds-ssm"&gt;GitHub Repo&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;🐦 Follow me on &lt;a href="https://twitter.com/ninan_phillip"&gt;Twitter&lt;/a&gt; if you would like to see more content like this! 🐦&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Today, I am going to show you how to provision an RDS instance using the AWS CDK. We will set up an AWS Secret and System Parameter that can be used to allow other resources to connect without using plaintext credentials. Never keep database credentials in plaintext!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Table Of Contents&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Introduction&lt;/li&gt;
&lt;li&gt;Check Out a Starter Project&lt;/li&gt;
&lt;li&gt;Update Dependencies&lt;/li&gt;
&lt;li&gt;Add a Database Secret&lt;/li&gt;
&lt;li&gt;Create a System Parameter&lt;/li&gt;
&lt;li&gt;Load Default Security Group&lt;/li&gt;
&lt;li&gt;Optionally Open Access From Your IP&lt;/li&gt;
&lt;li&gt;Configure  RDS Instance&lt;/li&gt;
&lt;li&gt;Output RDS Endpoint&lt;/li&gt;
&lt;li&gt;Deploy&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Check Out a Starter Project
&lt;/h2&gt;

&lt;p&gt;We are going to start from &lt;a href="https://blog.phillipninan.com/insider-secrets-of-aws-cdk-the-base-stack"&gt;my last post&lt;/a&gt;, here is the &lt;a href="https://github.com/fourgates/aws-cdk-base"&gt;GitHub Repo&lt;/a&gt;. We want to start with a base stack. A base stack is where you should keep your stateful resources. Since a database cannot be easily re-constructed you should consider this stateful. We will be updating the base stack by adding an RDS database. &lt;/p&gt;

&lt;h2&gt;
  
  
  Update Dependencies
&lt;/h2&gt;

&lt;p&gt;First, we need to update the &lt;code&gt;dependencies&lt;/code&gt; in &lt;code&gt;package.json&lt;/code&gt;. We are going to need some new dependencies for this tutorial. Note, you should try to keep all the CDK dependency versions the same.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  "dependencies": {
    ...
    "@aws-cdk/aws-rds": "1.95.1",
    "@aws-cdk/aws-secretsmanager": "1.95.1",
    "@aws-cdk/aws-ssm": "1.95.1"
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Add a Database Secret
&lt;/h2&gt;

&lt;p&gt;Next, we will start to update the base stack! First, we need to set up a secret and a system parameter. You should never keep plaintext credentials in plaintext or in source control. The &lt;a href="https://aws.amazon.com/secrets-manager/"&gt;AWS Secrets Manager&lt;/a&gt; allows you to provide credentials to a number of other AWS resources in a secure way. Let's add the secret.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    // first, lets generate a secret to be used as credentials for our database
    const databaseCredentialsSecret = new secretsManager.Secret(this, `${props?.stage}-DBCredentialsSecret`, {
      secretName: `${props?.stage}-credentials`,
      generateSecretString: {
        secretStringTemplate: JSON.stringify({
          username: 'postgres',
        }),
        excludePunctuation: true,
        includeSpace: false,
        generateStringKey: 'password'
      }
    });    

    // lets output a few properties to help use find the credentials 
    new cdk.CfnOutput(this, 'Secret Name', { value: databaseCredentialsSecret.secretName }); 
    new cdk.CfnOutput(this, 'Secret ARN', { value: databaseCredentialsSecret.secretArn }); 
    new cdk.CfnOutput(this, 'Secret Full ARN', { value: databaseCredentialsSecret.secretFullArn || '' });  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A couple of notes here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This is going to generate a password for the username &lt;code&gt;postgres&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;We are using a few &lt;code&gt;CfnOutput&lt;/code&gt;s to print some of the secret resource values. This will allow you to either identify which secret we just created or be able to access it via the AWS CLI. Note, this will not actually output a password! These values will be output in the terminal when you deploy your infrastructure. &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Create a System Parameter
&lt;/h2&gt;

&lt;p&gt;Next, we can simply create a system parameter with the secret. You will use this service to provide other AWS services with credentials to connect to RDS.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    // next, create a new string parameter to be used
    new ssm.StringParameter(this, 'DBCredentialsArn', {
      parameterName: `${props?.stage}-credentials-arn`,
      stringValue: databaseCredentialsSecret.secretArn,
    });      
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Load Default Security Group
&lt;/h2&gt;

&lt;p&gt;Our next step will be to get the VPC default security group. The database should be in a security group so that we can set up connectivity between other resources deployed in a VPC.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    // get the default security group
    let defaultSecurityGroup = SecurityGroup.fromSecurityGroupId(this, "SG", vpc.vpcDefaultSecurityGroup);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Optionally Open Access From Your IP
&lt;/h2&gt;

&lt;p&gt;You can optionally add a rule to allow access to the database from your IP. &lt;strong&gt;NOTE THIS IS NOT SECURE&lt;/strong&gt;! You should always put your database in a private subnet! This part is for educational purposes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    if(props?.yourIpAddres){
      // your to access your RDS instance!
      defaultSecurityGroup.addIngressRule(ec2.Peer.ipv4(props.yourIpAddres), ec2.Port.tcp(5432), 'allow 5432 access from my IP');
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Configure  RDS Instance
&lt;/h2&gt;

&lt;p&gt;Now, let us configure and create our RDS instance.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    // finally, lets configure and create our database!
    const rdsConfig: rds.DatabaseInstanceProps = {
      engine: rds.DatabaseInstanceEngine.postgres({ version: rds.PostgresEngineVersion.VER_12_3 }),
      // optional, defaults to m5.large
      instanceType: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.SMALL),
      vpc,
      // make the db publically accessible
      vpcSubnets: {
        subnetType: ec2.SubnetType.PUBLIC,
      },
      instanceIdentifier: `${props?.stage}`,
      maxAllocatedStorage: 200,
      securityGroups: [defaultSecurityGroup],
      credentials: rds.Credentials.fromSecret(databaseCredentialsSecret), // Get both username and password from existing secret
    }

    // create the instance
    this.rdsInstance = new rds.DatabaseInstance(this, `${props?.stage}-instance`, rdsConfig);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A couple of notes here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We are putting this into a public subnet. &lt;strong&gt;THIS IS NOT SECURE&lt;/strong&gt;. You should always put your database in a private subnet. We are doing this for educational purposes. &lt;/li&gt;
&lt;li&gt;I am creating the smaller database possible to save on costs. &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Output RDS Endpoint
&lt;/h2&gt;

&lt;p&gt;Lastly, let's output the RDS endpoint so you can actually connect publically. Again, this is just for educational purposes. &lt;strong&gt;ALWAYS KEEP YOUR DATABASE IN A PRIVATE SUBNET.&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;    // output the endpoint so we can connect!
    new cdk.CfnOutput(this, 'RDS Endpoint', { value: this.rdsInstance.dbInstanceEndpointAddress });     
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Deploy
&lt;/h2&gt;

&lt;p&gt;That's it! Synthesize and deploy your code and you will have a provisioned database! This may take some time to come up.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cdk synth
cdk deploy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;To get the credentials to connect to your new database you can either use the &lt;a href="https://docs.aws.amazon.com/cli/latest/reference/secretsmanager/get-secret-value.html"&gt;CLI&lt;/a&gt; using the &lt;code&gt;CfnOutput&lt;/code&gt; or you can manually find it in your AWS Secrets Manager console. In my subsequent posts, I will be using the RDS tutorial as a starting point for other resources to access it. Enjoy! 🍺 &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;TLDR:&lt;/strong&gt; Checkout the &lt;a href="https://github.com/fourgates/aws-cdk-rds-ssm"&gt;GitHub Repo&lt;/a&gt; with the complete code.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;🐦 Follow me on &lt;a href="https://twitter.com/ninan_phillip"&gt;Twitter&lt;/a&gt; if you would like to see more content like this! 🐦&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Interested in having a 1:1 chat with me over this story, or AWS in general? Head over to &lt;a href="https://www.hiretheauthor.com/phillip"&gt;Hire The Author&lt;/a&gt; and let’s connect!&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>aws</category>
      <category>cloud</category>
    </item>
    <item>
      <title>Building a SaaS Product - (1) Setting Up the Project (Angular, Express.js)</title>
      <dc:creator>Phillip Ninan</dc:creator>
      <pubDate>Thu, 18 Mar 2021 04:42:01 +0000</pubDate>
      <link>https://dev.to/ninan_phillip/building-a-saas-product-1-setting-up-the-project-angular-express-js-1mci</link>
      <guid>https://dev.to/ninan_phillip/building-a-saas-product-1-setting-up-the-project-angular-express-js-1mci</guid>
      <description>&lt;p&gt;For the past several months, I have been developing a SaaS product. This is my first post in a series to show you how to build your own product and deploy it to AWS. We will be creating an Angular frontend, Express.js backend, and using DynamoDb database. I will show you how to use Docker to containerize each component, and then deploying it on AWS. This post will show you how to set up a modular codebase and scaffold all the necessary components. &lt;/p&gt;

&lt;p&gt;Buckle up!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TLDR&lt;/strong&gt; - Here is a link to my &lt;a href="https://github.com/fourgates/blog-saas-starter.git" rel="noopener noreferrer"&gt;Github&lt;/a&gt; with the given code. &lt;/p&gt;

&lt;h2&gt;
  
  
  Twelve-Factor App
&lt;/h2&gt;

&lt;p&gt;We will be following the &lt;a href="https://12factor.net" rel="noopener noreferrer"&gt;Twelve-Factor App&lt;/a&gt; methodology. This is a framework to help you build software-as-a-service (SaaS). In setting up this project, we will be demonstrating the first two principles, Codebase and Dependencies. Our codebase will be tracked in source control and each component will be able to be developed, built, and deployed independently. &lt;/p&gt;

&lt;h2&gt;
  
  
  Frontend - Angular
&lt;/h2&gt;

&lt;p&gt;In my &lt;a href="https://pninan.hashnode.dev/how-to-containerize-an-angular-app" rel="noopener noreferrer"&gt;previous blog post&lt;/a&gt;, I wrote about how to containerize an Angular application. We will use that tutorial as a starter for this frontend.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# clone my git repo
git clone https://github.com/fourgates/blog-docker-angular-container-intro.git
# rename the folder to webapp
mv blog-docker-angular-container-intro webapp
cd webapp
# build the docker image
docker-compose build node
# remove my git repo
rm -fr .git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Backend - Express.js
&lt;/h2&gt;

&lt;p&gt;In another &lt;a href="https://pninan.hashnode.dev/how-to-containerize-expressjs" rel="noopener noreferrer"&gt;separate previous blog post&lt;/a&gt;, I showed you how to containerize an Express.js application. We will use that tutorial as a starter for the backend.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# clone my git repo
git clone https://github.com/fourgates/blog-express-ts-docker.git
# rename the folder to api
mv blog-express-ts-docker api
cd api
# build the docker image
docker-compose build
# remove my git repo
rm -fr .git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Database - DynamoDb
&lt;/h2&gt;

&lt;p&gt;I third &lt;a href="https://pninan.hashnode.dev/how-to-containerize-dynamodb" rel="noopener noreferrer"&gt;previous blog post&lt;/a&gt;, I taught you how to containerize a DynamoDb database. We will use that tutorial as a starter for the development database. We will modify the Express API &lt;code&gt;docker-compose.yml&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;version: '3.7'

services:
  express:
    build:
      context: .
      dockerfile: Dockerfile  
    image: express/builder:0.0.1
    container_name: express-container
    ports:
      - '8080:8080'
    volumes:
      - ./src:/usr/src/app/src 
    command: npm run start
  ddb:
    container_name: dynamodb-container
    image: amazon/dynamodb-local
    ports:
      - "8000:8000"
    volumes:
      - dynamodata:/home/dynamodblocal
    command: "-jar DynamoDBLocal.jar -sharedDb -dbPath ."
volumes:
  dynamodata: {}    
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A couple of notes on this structure:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;webapp&lt;/code&gt; - this is where the Angular frontend code is&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;api&lt;/code&gt; - this will be for the Express.js backend&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Start Your App!
&lt;/h2&gt;

&lt;p&gt;Once you have all of your docker images created you should be ready to start each component! You can open three terminals and run &lt;code&gt;docker-compose up dev&lt;/code&gt; in each components folder (webapp, api). Or you can use the &lt;code&gt;-d&lt;/code&gt; (disconnect) flag to use a single terminal to run all three commands&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Pro Tip - I love &lt;a href="https://code.visualstudio.com/download" rel="noopener noreferrer"&gt;VS Code&lt;/a&gt;! I usually open a VS Code instance / window for the frontend and backend (2 total). You can then use the terminal in VS Code to start your container while you develop! This way your code and terminal are all in one place. I also use the VS Code &lt;a href="https://marketplace.visualstudio.com/items?itemName=johnpapa.vscode-peacock" rel="noopener noreferrer"&gt;peacock plugin&lt;/a&gt; to give a different color to each window.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1612323954821%2FwCflChZ5V.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1612323954821%2FwCflChZ5V.png" alt="Screen Shot 2021-02-02 at 10.43.41 PM.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Git Init
&lt;/h2&gt;

&lt;p&gt;Optionally but highly recommended,  navigate to the root directory and initialized a new git repo. Run the following commands in the root directory (the parent folder of &lt;code&gt;api&lt;/code&gt;, &lt;code&gt;db&lt;/code&gt;, and &lt;code&gt;webapp&lt;/code&gt;). You will first need to create a new git repo. &lt;a href="https://github.com" rel="noopener noreferrer"&gt;Github&lt;/a&gt; is a great place to get started!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;echo "# My SaaS Product" &amp;gt;&amp;gt; README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin YOUR_GIT_REPO
git push -u origin main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Twelve-Factor App - Codebase
&lt;/h2&gt;

&lt;p&gt;We have successfully implemented the &lt;a href="https://12factor.net/codebase" rel="noopener noreferrer"&gt;first principle&lt;/a&gt; of the Twelve-Factor App, &lt;code&gt;Codebase&lt;/code&gt;.  This principle states that you should have one codebase tracked in source control. If you have more than one codebase this is typically no longer considered a single app, but a distributed system. There is nothing wrong with a distributed system but when you are first building a SaaS product you want to keep things simple and allow a developer to check out one codebase and get started ASAP. As your product grows you may find a use case for additional codebases. &lt;/p&gt;

&lt;h2&gt;
  
  
  Twelve-Factor App - Dependencies
&lt;/h2&gt;

&lt;p&gt;The &lt;a href="https://12factor.net/dependencies" rel="noopener noreferrer"&gt;second principle&lt;/a&gt; of the Twelve-Factor App is &lt;code&gt;Dependencies&lt;/code&gt;. This principle says that an app should never rely on the implied existence of system-wide packages. If the frontend and backend are deployed in two different environments this may break your system. You should be able to check out the codebase, utilize a dependency manager, and get started! We are using a mix of Node Package Manager (&lt;code&gt;npm&lt;/code&gt;) and Docker. Both of these tools explicitly document the dependencies for each component of our SaaS product. NPM uses &lt;code&gt;package.json&lt;/code&gt; to document the dependencies for our node components. Our &lt;code&gt;Dockerfile&lt;/code&gt; describes how our Docker images should be built. Each component can be developed, built, and deployed independently. &lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion!
&lt;/h2&gt;

&lt;p&gt;That's it! If you run &lt;code&gt;docker-compose up&lt;/code&gt; in each folder you will have successfully set up three components in our stack! Congrats!  &lt;/p&gt;

&lt;h2&gt;
  
  
  Code
&lt;/h2&gt;

&lt;p&gt;Here is a link to my &lt;a href="https://github.com/fourgates/blog-saas-starter.git" rel="noopener noreferrer"&gt;Github&lt;/a&gt; with the given code. &lt;/p&gt;

</description>
      <category>saas</category>
      <category>angular</category>
      <category>express</category>
      <category>node</category>
    </item>
    <item>
      <title>Getting Started with Express.js in 5 minutes</title>
      <dc:creator>Phillip Ninan</dc:creator>
      <pubDate>Fri, 12 Mar 2021 04:58:15 +0000</pubDate>
      <link>https://dev.to/ninan_phillip/getting-started-with-express-js-in-5-minutes-4c4j</link>
      <guid>https://dev.to/ninan_phillip/getting-started-with-express-js-in-5-minutes-4c4j</guid>
      <description>&lt;p&gt;Welcome to my first post in my &lt;a href="https://expressjs.com"&gt;Express.js&lt;/a&gt; series. Today, I am going to show you how to spin up a new express server in a matter of minutes. &lt;/p&gt;

&lt;p&gt;Express.js is one of my favorite &lt;a href="https://nodejs.org/en/"&gt;node&lt;/a&gt; frameworks. It is quick and simple while being very flexible. There is a ton of &lt;a href="https://expressjs.com/en/guide/routing.html"&gt;community support&lt;/a&gt; and many &lt;a href="https://expressjs.com/en/resources/frameworks.html"&gt;popular frameworks&lt;/a&gt; were built on top of it. You can find plenty of &lt;a href="https://expressjs.com/en/guide/using-middleware.html"&gt;examples of middleware&lt;/a&gt; to help with common use cases such as decoration, authentication, error handling, etc. It's a great framework to help build apps quickly and securely. I have built several APIs using express. Let's get started!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TLDR&lt;/strong&gt;: Here is a working example in my &lt;a href="https://github.com/fourgates/blog-express-ts-docker/tree/part-1-init"&gt;GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Prereq -- make sure node is installed. If not, you will need to &lt;a href="https://nodejs.org/en/download/"&gt;download&lt;/a&gt; and install it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node --version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;First, create a folder for the demo.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir express-demo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, initialize the new node app.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm init -y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, install express.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install express
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We will now create the entry point to get an express server started. Either open up your favorite text editor or continue using your terminal (my recommendation). We are going to make a &lt;code&gt;src&lt;/code&gt; folder with a file named &lt;code&gt;index.js&lt;/code&gt; inside of it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir src
cd src
nano index.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Copy in the following text into &lt;code&gt;index.js&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const express = require( "express" );
const app = express();
const port = 8080; // default port to listen

// define a route handler for the default home page
app.get( "/", ( req, res ) =&amp;gt; {
    res.send( "Hello world!" );
} );

// start the Express server
app.listen( port, () =&amp;gt; {
    console.log( `server started at http://localhost:${ port }` );
} );
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(If you are using &lt;code&gt;nano&lt;/code&gt;, &lt;code&gt;CTRL + X&lt;/code&gt; to exit edit mode. Next, enter &lt;code&gt;Y&lt;/code&gt; to "save modified buffer". Finally, hit &lt;code&gt;enter&lt;/code&gt; to save with the current file name.)&lt;/p&gt;

&lt;p&gt;Lastly, we need to update &lt;code&gt;package.json&lt;/code&gt; to instruct npm on how to run your application. We will change &lt;code&gt;main&lt;/code&gt; to point to the newly created &lt;code&gt;src/index.js&lt;/code&gt; and add a &lt;code&gt;start&lt;/code&gt; script.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd .. 
nano package.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is what the changes should look like.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  "main": "src/index.js",
  "scripts": {
    "start": "node .",
    "test": "echo \"Error: no test specified\" &amp;amp;&amp;amp; exit 1"
  },
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it! Express.js is now ready! All you need do to is start it up.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should see the following text.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;server started at http://localhost:8080
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In a new terminal, you should be able to &lt;code&gt;curl&lt;/code&gt; and see "Hello world".&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl localhost:8080
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Alternatively, if you navigate to &lt;code&gt;http:localhost:8080&lt;/code&gt; in your favorite web browser you should see "Hello world"!&lt;/p&gt;

&lt;p&gt;Here is a working example in my &lt;a href="https://github.com/fourgates/blog-express-ts-docker/tree/part-1-init"&gt;GitHub&lt;/a&gt;. I hope you enjoyed this tutorial! You didn't even have to leave your terminal. My next post in this series will teach you how to convert this project to &lt;a href="https://www.typescriptlang.org/"&gt;TypeScript&lt;/a&gt;. Also, I will be writing about some useful middleware I have written. &lt;/p&gt;

&lt;p&gt;Cheers!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Land a Software Job in 6 Months!</title>
      <dc:creator>Phillip Ninan</dc:creator>
      <pubDate>Thu, 11 Mar 2021 04:32:12 +0000</pubDate>
      <link>https://dev.to/ninan_phillip/land-a-software-job-in-6-months-8c9</link>
      <guid>https://dev.to/ninan_phillip/land-a-software-job-in-6-months-8c9</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;I have JS, PHP, HTML &amp;amp; CSS, but where would you suggest I go next? There’s so much to learn and it’s very confusing. I’m really scared of getting things wrong. Or asking for a road map if you like. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is a hard question to answer. You need to ask yourself, "What are my goals"?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Do you want to be able to build apps? Web apps? &lt;/li&gt;
&lt;li&gt;Do you want to design very pretty-looking websites? &lt;/li&gt;
&lt;li&gt;Do you want to want to make cool websites and get them to be on the first page of Google (SEO)? &lt;/li&gt;
&lt;li&gt;Are you interested in AI or ML? Do you like databases?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once you figure out your goal(s), you can put a plan in place. I can help you figure out what steps you should take forward! All you need are some stepping stones. We can create a road map on how to accomplish your goal. Here is a simple roadmap for becoming a web application developer. &lt;/p&gt;

&lt;p&gt;🐦 Follow me on &lt;a href="https://twitter.com/ninan_phillip"&gt;Twitter&lt;/a&gt; to see even more content! 🐦&lt;/p&gt;

&lt;h2&gt;
  
  
  !IMPORTANT!
&lt;/h2&gt;

&lt;p&gt;This is a high-level roadmap. This is not intended to turn you into an expert. This is ONE of MANY ways to HELP you land an entry-level web developer job. I have close to a decade of experience writing code. I regularly interview entry-level developers. If you were to complete each of these steps, absorb the material, and be able to speak intelligently about these topics I would be impressed. Take this advice with a grain of salt.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Learn HTML and CSS
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.freecodecamp.org/news/the-html-handbook/"&gt;FreeCodeCamp&lt;/a&gt; is a great resource for this.  HTML and CSS is the foundation for any web application. Allocate 2-3 weeks for this.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Recreate 3 Popular Websites
&lt;/h2&gt;

&lt;p&gt;Develop a landing page(s) using only HTML and CSS. &lt;a href="https://www.apple.com"&gt;Apple&lt;/a&gt;, &lt;a href="https://github.com"&gt;GitHub&lt;/a&gt;, and &lt;a href="https://www.netflix.com"&gt;Netflix&lt;/a&gt; are great choices! Understanding how popular websites are built will allow you to follow great patterns when you develop your own. Allocate 1-2 weeks to accomplish this.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Learn JavaScript and NPM
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.freecodecamp.org/news/learn-javascript-full-course/"&gt;FreeCodeCamp&lt;/a&gt; and &lt;a href="https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web/JavaScript_basics"&gt;MDN&lt;/a&gt; are great resources for this. All modern websites utilize some sort of JavaScript framework. &lt;a href="https://www.freecodecamp.org/news/tag/npm/"&gt;Node and NPM&lt;/a&gt; are tools used to work with these frameworks. They allow you to use libraries and tools that someone else has already written! Allocate 2-3 weeks.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Recreate 2 Popular Websites with JavaScript
&lt;/h2&gt;

&lt;p&gt;Pick 2 complex projects and recreate their basic functionality using JavaScript, HTML, and CSS. &lt;a href="https://soundcloud.com"&gt;Soundcloud&lt;/a&gt; and &lt;a href="https://twitter.com"&gt;Twitter&lt;/a&gt; are great examples. Allocate 2-3 weeks.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Learn How Computers and the Internet Works
&lt;/h2&gt;

&lt;p&gt;Search &lt;a href="https://youtube.com"&gt;YouTube&lt;/a&gt; and &lt;a href="https://wikipedia.com"&gt;Wikipedia&lt;/a&gt; and focus on the Application layer, HTTP, and how modern web apps work. You need to understand the basics of how web applications communicate. Allocate 1-2 weeks.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Learn Git and Deploying
&lt;/h2&gt;

&lt;p&gt;All software projects should use source control. &lt;a href="https://www.atlassian.com/git"&gt;Atlassian&lt;/a&gt; has great git tutorials. Deploy your projects to &lt;a href="https://www.netlify.com"&gt;Netlify&lt;/a&gt; or &lt;a href="https://vercel.com"&gt;Vercel&lt;/a&gt;. Allocate 1-2 weeks.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Learn NodeJs and Express
&lt;/h2&gt;

&lt;p&gt;Use &lt;a href="https://expressjs.com/en/starter/installing.html"&gt;official tutorials&lt;/a&gt;, then &lt;a href="https://youtube.com"&gt;YouTube&lt;/a&gt; and &lt;a href="https://stackoverflow.com"&gt;StackOverflow&lt;/a&gt; if you don't understand something. I have a getting started tutorial &lt;a href="https://blog.phillipninan.com/getting-started-with-expressjs-in-5-minutes"&gt;here&lt;/a&gt;. Express and Node are great frameworks for build web applications QUICKLY. Allocate 2 weeks.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. Learn ReactJS and Redux.
&lt;/h2&gt;

&lt;p&gt;I am a big advocate for Angular. But I think ReactJS is in the &lt;a href="https://javascript.plainenglish.io/top-5-in-demand-javascript-frameworks-for-front-end-development-in-2020-a59c4340d082"&gt;biggest demand right now&lt;/a&gt;. &lt;a href="https://epicreact.dev"&gt;Kent C. Dodds&lt;/a&gt; has a great course. &lt;a href="https://www.udemy.com/topic/react/"&gt;Udemy&lt;/a&gt; also has some great courses. Allocate 3 weeks.&lt;/p&gt;

&lt;h2&gt;
  
  
  9. Learn GraphQL
&lt;/h2&gt;

&lt;p&gt;Use &lt;a href="https://graphql.org/graphql-js/"&gt;official tutorials&lt;/a&gt; and YouTube (Udemy if needed). Then transfer your created apps to GraphQL. It should be relatively easy to migrate a small project to GraphQL, especially if you've gotten this far! Allocate 1 week.&lt;/p&gt;

&lt;h2&gt;
  
  
  10. Learn TypeScript
&lt;/h2&gt;

&lt;p&gt;Learn it using &lt;a href="https://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes.html"&gt;official docs&lt;/a&gt;, YouTube &amp;amp; Udemy if needed. After, transfer all created apps to the TypeScript. I have written a &lt;a href="https://blog.phillipninan.com/how-to-convert-expressjs-to-typescript"&gt;great article&lt;/a&gt; describing how to convert ExpressJS to TypeScript. Allocate 1 week.&lt;/p&gt;

&lt;h2&gt;
  
  
  11. Build 2 Complex Applications
&lt;/h2&gt;

&lt;p&gt;Pick a popular service and recreate the core functionality using learned stack: ReactJS, &lt;a href="https://www.toptal.com/react/navigating-the-react-ecosystem"&gt;React Ecosystem&lt;/a&gt;, GraphQL, TypeScript, and ExpressJS. Then you will deploy it and put it on your resume. Allocate 2-4 weeks.&lt;/p&gt;

&lt;h2&gt;
  
  
  12. Create a resume, LinkedIn profile and apply for jobs
&lt;/h2&gt;

&lt;p&gt;It should take you 1-4 weeks to land a job.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This should take you roughly ~6 months. This roadmap is not meant to make you an expert. But it should make you competent enough to land an entry-level software developer job. If you complete this roadmap I am very confident that you will be a very marketable developer! Good Luck! Reach out to me for ANY help!&lt;/p&gt;

&lt;p&gt;🐦 Follow me on &lt;a href="https://twitter.com/ninan_phillip"&gt;Twitter&lt;/a&gt; to see even more content! 🐦&lt;/p&gt;

&lt;p&gt;This roadmap was inspired by &lt;a href="https://twitter.com/nickbulljs/status/1358326430204125185"&gt;Nick Bull&lt;/a&gt;!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>html</category>
      <category>react</category>
      <category>typescript</category>
    </item>
    <item>
      <title>How to Write Great Tests!</title>
      <dc:creator>Phillip Ninan</dc:creator>
      <pubDate>Thu, 04 Feb 2021 23:59:01 +0000</pubDate>
      <link>https://dev.to/ninan_phillip/how-to-write-great-tests-4719</link>
      <guid>https://dev.to/ninan_phillip/how-to-write-great-tests-4719</guid>
      <description>&lt;p&gt;In my  &lt;a href="https://pninan.hashnode.dev/junit-for-dummies-nifty-shuffle-sort-testing"&gt;previous post&lt;/a&gt;, I discussed a nifty sorting test. Today, I am going to teach you how to write great tests! When I write a new &lt;a href="https://junit.org/junit5/"&gt;JUnit&lt;/a&gt; test I follow the same formula. This allows my tests to be written and read in a consistent manner. It also helps me write tests faster. I would like to share my format with you today!&lt;/p&gt;

&lt;h2&gt;
  
  
  The File
&lt;/h2&gt;

&lt;p&gt;The first thing I do is create a new test file/class in my project's test package and create the test method. All my tests end with &lt;code&gt;Test&lt;/code&gt; so it is easy to find corresponding classes. A class named &lt;code&gt;SomeService&lt;/code&gt; should have a counterpart named &lt;code&gt;SomeServiceTest&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Next, I make sure I give my test a good name. I personally prefer to omit the word &lt;code&gt;test&lt;/code&gt; it since its redundant in a test class. The name of the test should describe what is being tested. Make you can easily differentiate similar tests.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public SomeServiceTest{
    @Test
    public void sortByPopularVoteDesc() {

    }
    @Test
    public void sortByPopularVoteAsc() {

    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Outline
&lt;/h2&gt;

&lt;p&gt;Next, I put some boilerplate inside of my method. This is the same format I use for all my tests. I set up my test, I call a function, finally, I use some sort of assertion or verify to ensure the expected results.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public TestClass{
    @Test
    public void sortByPopularVote() {
      // setup
      // test
      // assert/validate
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's discuss some of these components. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;setup&lt;/code&gt; - This is where you should prepare your code to be tested.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;test&lt;/code&gt; - This is where you should call the function being tested. This can be good to point out if you call multiple functions in your test. &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;assert/validate&lt;/code&gt; - This is where you actually use an &lt;code&gt;assert&lt;/code&gt; or &lt;code&gt;validate&lt;/code&gt; function to ensure the actual output matches what you expect. &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Setup The Test
&lt;/h2&gt;

&lt;p&gt;Finally, I simply fill in the blanks. If my setup is similar to &lt;strong&gt;all&lt;/strong&gt; other tests I abstract this logic to a &lt;code&gt;@Before&lt;/code&gt; function. This function gets invoked before each test. If you have a common setup between several tests, but not all of them, it is also a common practice to write a private function to encapsulate specific setup instructions. Either option makes the setup for common tests more reusable. If you have to make a change in setting up your tests you only have to make it in one place. This is very useful when a refactor breaks a certain set of tests.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public TestClass{
  private List&amp;lt;SortableObj&amp;gt; expected;
  private final SortableObj first = new SortableObj();
  private final SortableObj second = new SortableObj();
  private final SortableObj third = new SortableObj();
  private final SortableObj fourth = new SortableObj();

   @Before
   public void before{
     // some decoration on objects
     // ...
     expected = Arrays.asList(first, second, third, fourth);
   }

    @Test
    public void sortByPopularVote() {
      // setup
      List&amp;lt;SortableObj&amp;gt; actual = Arrays.asList(fourth, third, first, second);
      // test
      Collections.sort(actual);
      // assert/validate
      assertThat(actual).isEqualTo(expected);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Testing Nomenclature
&lt;/h2&gt;

&lt;p&gt;Please note the use of the variable names &lt;code&gt;expected&lt;/code&gt; and &lt;code&gt;actual&lt;/code&gt;. These are keywords commonly associated with writing tests and make them more easily readable. &lt;strong&gt;You want the &lt;code&gt;actual&lt;/code&gt; object returned from a function to match the &lt;code&gt;expected&lt;/code&gt; value.&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;expected&lt;/code&gt; - This is the name of the variable for what you want your output to look like. In this example, we want a list to be in a certain order.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;actual&lt;/code&gt; - This is the name of the variable to use for the output of the function under test. It is the "actual" output to the function. &lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Nomenclature - The devising or choosing of names for things, especially in a science or other discipline. In the context of software, this deals with the consistent naming of API endpoints, responses, variables, functions, and documentation. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Using this format you should be able to write more consistent tests in an efficient manner. This allows you to implement more maintainable code. I hope you enjoyed this post! Check out my series on  &lt;a href="https://hashnode.com/series/testing-your-code-ckeoueav200y5kps19v3w54pa"&gt;JUnit tests&lt;/a&gt;!&lt;/p&gt;

&lt;p&gt;Follow me on &lt;a href="https://twitter.com/ninan_phillip"&gt;Twitter&lt;/a&gt; if you would like to keep up to date with my latest software content!&lt;/p&gt;

</description>
      <category>junit</category>
      <category>java</category>
      <category>testing</category>
      <category>tdd</category>
    </item>
  </channel>
</rss>
