All Categories

  • How to Delete Data from MongoDB with Node.js and Mongoose

    8/11/2020 -
    This blog will show a tutorial about how to delete data from MongoDB by using Node.js with Mongoose. Mongoose is the Object Data Modeling library for MongoDB and Node.js. It provides functions for schema, query building, and more. If you don't use Mongoose to access MongoDB with Node.js, then you can use the MongoDB package for Node.js directly.  Get Start First, initialize a new npm package, we'll create a new package and new file, and add our code for how to insert data to MongoDB. npm init -y Next, let's install the mongoose package, this will be the only package we'll use for this tutorial.  npm install --save mongoose Create an index.js, we'll add our code to this file to connect to MongoDB and insert data to the Database. Connect to the MongoDB Now, the following is a sample code to connect to MongoDB.
    MongoDBNode.jsMongoose
  • How to Insert Data into MongoDB with Node.js and Mongoose

    7/11/2020 -
    This blog will show a tutorial about how to insert data into MongoDB by using Node.js with Mongoose. Mongoose is the Object Data Modeling library for MongoDB and Node.js. It provides functions for schema, query building, and more. If you don't use Mongoose to access MongoDB with Node.js, then you can use the MongoDB package for Node.js directly.  Get Start First, initialize a new npm package, we'll create a new package and new file, and add our code for how to insert data to MongoDB. npm init -y Next, let's install the mongoose package, this will be the only package we'll use for this tutorial.  npm install --save mongoose Create an index.js, we'll add our code to this file to connect to MongoDB and insert data to the Database. Connect to the MongoDB Now, the following is a sample code to connect to MongoDB.
    Node.jsMongooseMongoDB
  • How to Find Record from MongoDB with Node.js and Mongoose

    9/11/2020 -
    This blog will show a tutorial about how to find data into MongoDB by using Node.js with Mongoose. Mongoose is the Object Data Modeling library for MongoDB and Node.js. It provides functions for schema, query building, and more. If you don't use Mongoose to access MongoDB with Node.js, then you can use the MongoDB package for Node.js directly.  Get Start First, initialize a new npm package, we'll create a new package and new file, and add our code for how to insert data to MongoDB. npm init -y Next, let's install the mongoose package, this will be the only package we'll use for this tutorial.  npm install --save mongoose Create an index.js, we'll add our code to this file to connect to MongoDB and insert data to the Database. Connect to the MongoDB Now, the following is a sample code to connect to MongoDB.
    Node.jsMongooseMongoDB
  • How to Use nconf for Environment Configuration at Node.js

    3/2/2020 -
    This blog shows how to use nconf for Node.js environment configuration. Environment config is needed in any coding language, for instance, the database endpoint for each of the environments, your development, and production should be different.  Install the nconf Now, use nconf is very easy, first add to your solution's dependency package. npm install nconf --save Use the nconf You can write a helper class like following to use nconf. First, you import the package to your file, load json file, then return the nconf. const nconf = require('nconf'); nconf.file('env.json'); exports.config = nconf; This JSON file will be your App's environment configuration, you can put all your configuration dependencies to this JSON file. Later, each of your environments just updates this JSON file to match that environment's config.
    Node.js
  • How to Setup MongoDB on Mac

    7/11/2020 -
    This blog shows how to set up MongoDB 4.4 Community version on Mac OS, also will create a simple database, table, and collection, and how to backup and store data by using mongoexport and mongoimport. Install MongoDB Server Install MongoDB on Mac is a little different compare to the Mac, you'll need brew to install the MongoDB, on this blog assume brew is already installed on Mac. Download Homebrew formula for MongoDB brew tap mongodb/brew Install MongoDB in macOS brew install mongodb-community@4.4 Install MongoDB Tools Starting from MongoDB 4.4, use brew will also install the mongodump, mongoexport, mongoimport and some other commands. Install MongoDB Compass MongoDB Compass is the GUI tool, you should install on your local development environment so you can connect to the MongoDB server and run the query from GUI.
    MongoDB
  • How to Setup MongoDB on Amazon Linux EC2

    2/11/2020 -
    This blog shows how to set up a MongoDB database environment on the cloud, AWS EC2 with Amazon Linux.  Pre requirement You'll need an AWS account, if you never set up an AWS account before, go here to create an AWS account. Create EC2 Instance First, we'll need to set up an EC2 instance, then we'll SSH into the EC2 instance and set up the MongoDB database. Create EC2 Instance with AWS Linux AMI. Choose t2.micro. During the setup everything as default is fine for this blog, we'll use default VPC, as long as the new EC2 can access the internet.  For the security group, we'll just open port 22, so we can SSH later to into EC2 for setup MongoDB.
    MongoDBEC2Linux
  • How to Update MongoDB Data with Node.js and Mongoose

    8/11/2020 -
    This blog will show a tutorial about how to update data into MongoDB by using Node.js with Mongoose. Mongoose is the Object Data Modeling library for MongoDB and Node.js. It provides functions for schema, query building, and more. If you don't use Mongoose to access MongoDB with Node.js, then you can use the MongoDB package for Node.js directly.  Get Start First, initialize a new npm package, we'll create a new package and new file, and add our code for how to insert data to MongoDB. npm init -y Next, let's install the mongoose package, this will be the only package we'll use for this tutorial.  npm install --save mongoose Create an index.js, we'll add our code to this file to connect to MongoDB and insert data to the Database. Connect to the MongoDB Now, the following is a sample code to connect to MongoDB.
    Node.jsMongoDBMongoose
  • How to Setting up DynamoDB Locally

    12/13/2020 -
    AWS DynamoDB is a document database that provides single-digit millisecond performance, it is a serverless database, which means you can focus on use applications to access the DynamoDB and AWS will manage the server for you. It's also available in multiple AWS regions and has built-in Cache DAX.  Another good reason to use DynamoDB is the free tier provided by DynamoDB. up to 25 GB storage, 25 write capacity units, and 25 read capacity units are free. Compare to MongoDB, depend on the MongoDB cloud provider it might be 500MB storage if you try to look for a free tier.  Now, in this blog I'll show how to set up DynamoDB locally, also show a few simple codes to access local DynamoDB. Download DynamoDB Go to this link from AWS to download DynamoDB, the different region has different DynamoDB file, so choose the region you'll be using for DynamoDB. After unzipping the file, run the following command.
    AWSDynamoDB
  • How to Increase AWS EBS Volume Size

    12/12/2020 -
    This quick note shows how to increase AWS EC2 Linux's EBS volume size. First, log in to AWS, and select the target EBS, update the size. The volume size will update right away, but you'll do the following. Next, ssh into the EC2 Linux instance, we would check the current Linux size. After ssh into the EC2, type the following command so we'll know does the increased volume had changed or not. lsblk Following is the sample result when you type lsblk. Here we'll know that you have size as 16G but current EBS only has 8G. nvme1n1 30G nvme0n1 16G |-----nvme0n1p1 8G Now, the following command will change the size to use maximum size base on the above sample result. After you run the command, your EBS should be 16G now.
    AWS
  • How to Create VPC with Public and Private Subnet

    2/12/2020 -
    This blog shows how to create VPC in scratch Create VPC Create 2 Subnets one for public Subnet and another for a private Subnet Create Internet Gateway Create a Route Table Create 2 EC2 Instances one public instance and another one is a private instance Setup NAT Gateway for private EC2 instance Create a VPC Go to VPC and click create VPC, start to enter information to create VPC. Enter any name for the name field IPv4 CIDR, enter IPv4 range as 10.0.0.0/16 Choose Amazon provided IPv6 CIDR block Tenancy, choose Default if wish to use as Tenancy after creating VPC, AWS will generate following AWS default services.
    EC2AWSVPC
  • Use VPC Flow Logs

    3/11/2020 -
    Create Flow logs Select the VPC to want to use flow logs, click action then click Create flow log. Setup Destination log group If you choose to send to CloudWatch logs, you'll have to set up a destination log group. Go to CloudWatch and choose Log groups. Set up IAM role for flow logs Click set up permission on the create VPC flow logs page, this UI will only show on old UI, which will create the following policy to enable flow logs to read and write to cloud watch.
    AWSVPC
  • VPC End Point - Use S3 from Private EC2 Instance

    2/20/2020 -
    This blog shows how to use VPC Endpoint from private EC2 Instance to S3 without going through the internet, with VPC Endpoint access s3 should be within AWS service which will be no charge. Attach IAM role to private EC2 Instance Since we'll need to access s3 from EC2 private instance, we'll need to set up an s3 full access role for EC2 instance.   Create a new role and select the AmazonS3FullAccess.
    S3VPC
  • How to Use C# Enum Flag

    12/12/2020 -
    A quick code snippet to show use enum flag by using the power of two. So you can define your enum and set the value as following, this will make the combine flag be unique. public enum MyType : uint { Undefined = 0, Type1 = 1, Type2 = 2, Type3 = 4, Type4 = 8, Type5 = 16 } Or you can use the bit shift if you don't want to count the number. public enum MyType2 : uint { Undefined = 0, Type1 = 1, Type2 = 2 << 0, Type3 = 2 << 1, Type4 = 2 << 2, Type5 = 2 << 3 } Following are few way how to use this enum. // set value var myvalue = MyType.Type1 | MyType.Type2; Console.WriteLine(myvalue); var myvalue2 = MyType2.Type1 | MyType2.Type2; Console.WriteLine(myvalue2); // check value if ((myvalue2 & MyType2.Type1) == MyType2.Type1) { Console.
    csharp
  • Create AWS Classic Load Balancer

    3/4/2020 -
    This blog shows how to use AWS classic Load Balancer from scratch, first we need to do some preparation. At the end of the setup, you'll set up 2 EC2 instances with the public subnet. Following are a list of preparation before setup the classic load balancer.
    AWS
  • How to Create AWS Organization - For Consolidated Billing

    2/11/2020 -
    If you just have 1 AWS account, you could just use that account for billing and development. However, if you have multiple AWS accounts, it is hard to manage each account's billing, so AWS has a way that is using AWS Organizations to consolidate billing. Assume that you have the following different AWS accounts. AWS Account - Use for Development AWS Account - Use for QA AWS Account - Use for Production For consolidated billing, we'll set up AWS Organization as following. AWS Account - Use as Root Account, and billing only AWS Account - Use for Development AWS Account - Use for QA AWS Account - Use for Production Go to the root account, or create a new AWS account and use as root account for billing.
    AWS
  • Use AWS Elastic IP Address

    4/9/2020 -
    This blog will show how to use AWS elastic IP to assign to EC Instance but before that... Why do you need to use an elastic IP address? Assume you have the following EC2 had set up, you use your EC2 as a web server and the public IP address is as follows. Now, if you stop your instance and start again. The EC2 instance public IP address changed! So this could an issue if you need to know this server's IP address for processing something else. You could use EC2 instance metadata to log the IP address somewhere, like using Lambda, or you could use elastic IP address I will show later. Following is how you use AWS elastic IP address.
    AWSEC2
  • How to Retrieve EC2 Instance Meta Information

    4/1/2020 -
    SSH into EC2 instance To retrieve EC2 instance meta information, once SSH into EC2 instance type following command. run with root privileges sudo su list all the metadata curl http://169.254.169.254/latest/meta-data Get EC2's hostname curl http://169.254.169.254/latest/meta-data/local-hostname Get EC2's user data curl http://169.254.169.
    EC2AWS
  • How to Setup AWS Application Load Balancer

    2/4/2020 -
    This blog will show how to create an AWS application load balancer with custom VPC's EC2 instances. Setup Custom VPC Create VPC Go to VPC and click create VPC, enter the VPC field as below example. Name tag: enter your VPC name IPv4 CIDR block: enter your CIDR block IP range IPv6 CIDR block: choose IPv6 Network Border Group Tenancy: Default (you can choose if you want to single-tenant, dedicated hardware or not) Create Subnet We'll need 2 subnets to create the Application Load Balancer. Name tag: enter any name VPC: choose the VPC just created Availability Zone: choose the availability zone IPv4 CIDR block: 172.0.1.
    AWSVPC
  • Angular2 Master/Detail Page Example

    12/11/2020 -
    This blog demo how to build angualr2 master/detail page, following is the template page for now. Anything under here will code which make above things happen.   package.json { "name": "news-app2", "version": "0.0.0", "license": "MIT", "angular-cli": {}, "scripts": { "start": "ng server", "postinstall": "typings install", "pree2e": "webdriver-manager update", "e2e": "protractor" }, "private": true, "dependencies": { "@angular/common": "2.0.0-rc.4", "@angular/compiler": "2.0.0-rc.4", "@angular/core": "2.0.0-rc.
    Angular2 Angular
  • Blocking Traffic from Specific IP Address with AWS Network ACL

    3/2/2020 -
    This blog shows few ways of use AWS Network ACLs to block traffic to your site. How to blocking traffic from a Specific IP address AWS has few ways to block specific targets to access your site, for example, Network ACL or WAF. So let's assume one of the examples, you have a web site running in EC2 instance as one web server, now there's one IP address you noticed and want to block the traffic. You can use the Network ACL as following. Find the Network ACL from EC2 First, you need to find out the Network ACL from EC2 instance. You can click Subnet from EC2, then click Network ACL. Find the IP address Next, you need to have an IP address. If you want to test your own machine's IPv4 Address, you can either google that what's my IP address or go to https://whatismyipaddress.com/ to check your Public IP address.
    EC2AWSNetwork ACL
  • How to Backup EC2 EBS Volume

    4/1/2020 -
    This blog shows how to backup EC2 instance and create another instance to the same region or different region. Create a snapshot from EC2 EBS volume Create snapshot Once the snapshot is complete should be able to check from the dashboard. Create an image from snapshot Once create an Image, then you can launch the EC2 instance from the image in the current region.
    EBSEC2