Posts

NestJS Basic Concepts (V 10.X)

Image
 Main Building Blocks Controller - Handle incoming request Services - Handle business logic Modules - Group together everything Pipes - Validate incoming data Filters - Handle incoming errors Guards - Handle authentication Interceptors - Adding extra data to incoming request or to response Repositories - Handle data stored in DB How to generate Nest project using Nest CLI? First, need to install Nest CLI on computer, npm install -g @nestjs/cli Then, create a new project using nest new <project_name> This will generate the boilerplate for the project The entry point of the application is main.ts file. It is calling main AppModule, 3 files attached with the main.ts , app.module.ts - The entry point app.controller.ts  app.service.ts Rest of the modules should be included to the AppModule as bellow,

Kubernetes for Micro Services

Image
(Special thanks to Stephen Grider) Cluster - Whole wrapper Node - A virtual machine Pod - Container wrapper. There can be multiple containers inside a Pod Deployment - Monitor set of Pods. If something down, then this will restart them to make sure it is running Service - Provide nice URLs for containers How to create a Pod directly? Create Pod using configuration file - kubectl apply -f posts.yml  Note: This apply use for any type of cluster change Example of posts.yml apiVersion : v1 kind : Pod metadata : name : posts spec : containers : - name : post image : dilumdarshana/posts:0.0.1 Get all pods running - kubectl get pods Delete Pods -  kubectl delete -f posts.yml General important Pod commands: kubectl exec -it <pod name> <command> kubectl logs <pod name> kubectl delete pod <pod name> kubectl describe pod <pod name> How to create Pods via deployment ? kubectl apply -f <deployement.yml> Example of deployment.yml apiVersion : apps/v1

Node-RED

Image
 Node-RED server can be spine using docker as bellow, - docker run --rm --net tulip-net -it -p 1880:1880 -v myNodeREDdata:/data   --name mynodered nodered/node-red It is important that run on specific network, if you have several docker containers running. Eg. MQTT or Mongo... How to run a MQTT broker, - docker run --rm --net tulip-net -p 8080:8080 -p 1883:1883 --name hivemq hivemq/hivemq4 How to run a Mongodb, docker run --rm --net tulip-net -d -p 27018:27017 --name nodered_mongo -e MONGO_INITDB_ROOT_USERNAME=admin -e MONGO_INITDB_ROOT_PASSWORD=admin mongo Node-RED can be installed new extensions as necessary. Use `Mange Pelette` link for that, dsfasdf

Angular 5

Angular 5 released a few days ago. Let's try to go through all the important features that we want to know, in order to create a super application. First, you need to install angular CLI to make your life easier. You can run the bellow code to install angular CLI as a global package,  npm install -g @angular/cli All the needed helps are located at https://github.com/angular/angular-cli . You can directly use the 'ng' commands provided there to create Component, Directive, Service, Interface, etc... When you use the tool, it will be inject all the import lines into the 'app-module' automatically. Before start looking into the Angular, you need to have some development tools installed in your computer. I prefer to use 'Microsoft Visual Code' which is free software from Microsoft. You can download the appropriate installer for your operating system from here  https://code.visualstudio.com/download Once you install VS Code, you may install the followin

Laravel 5.3

# Create a new project composer create-project --prefer-dist laravel/laravel <project-name> # Check existing version php artisan -V # Make controllers php artisan make:controller ProductController # Make models php artisan make:model <modal name> # Make views # Database Using migration script: - Migration scripts will be stored at 'database/migrations' folder - Can create a blueprint of migration script using,   php artisan make:migration <name of script to identify> --create=<table name>   eg. php artisan make:migration create_table_customer --create=customer - Can get the help using,    php artisan help make:migration - Can run all the migration scripts using,   php artisan migrate - Can rollback current change using,   php artisan migrate:rollback # Seeder - seeding database with test data using seed classes - Create seeding script   php artisan make:seeder <seeder name>   eg. php artisan make:seeder CustomerTable

Node Commands

# How install specific node version on Ubuntu -  https://github.com/nodesource/distributions/blob/master/README.md  npm commands:  npm init - To initalize the package. This will create package.json on the fly  npm install - This will look for package.json and install all the listed packages npm insall -g <package name> - To install packages globally npm install --save <package name> - To install packages locally, as well as add entry to package.json file npm install --save-dev <package name> - To install packages locally, as well as add entry to dev section in the package.json npm list -g --depth=0 - To list all the globally installed packages. Without depth, will list down all the installed packages and sub packages npm view cordova versions - List down all the released versions  npm uninstall --save <package name> - To  remove packages from locally. --save will remove entry from package.json npm cache clean - Delete data out of the

REST API using Node/Express/MongoDB

REST API How to initalize node app, - npm init - Will create basic setup including package.json - npm install express --save - Installing main tool express js. What --save means, it will update the package.json file for dependancy - npm install --save mongoose node-restful body-parser - General extra modules that need for REST which doesn't come up with express Task monitoring system (using gulp): Node change monitoring tool. Once do a change on the file system, app will restart automatically. - npm install -g gulp - npm install --save gulp - npm install --save-dev gulp-nodemon Note:     - npm global installations will keep in '/usr/local/lib/node_modules' in Mac. Refer Github for codes:  https://github.com/dilumdarshana/nodeREST