Tuesday, October 21, 2025

Debug node js file with visual studio code

With visual studio code, sometimes you may want to debug a node js file, but do not want to always enable debugger when you start node js files. 

In that case, you can set visual studio preference to 

Debug> javascript: Auto Attach Filter to 

onlyWithFlag

 

And then when you starts a node js file from terminal, set the --inspect flag will automatically enable debug for the current session. The below is an example

node --inspect myserver.js


If you do not want to enable js debugger, then just user

node myserver.js


Monday, September 29, 2025

Simple way to fix git .lock file already exist error when fetch or pull rebase a branch

 Not sure why sometimes git reports an error of .lock file already exists error in .git ref folder, although actually the file or even the mentioned folder does not exist.

Tried many ways mentioned in web but none of them works in my case. Clone and download all dependency packages again will take a lot of time and it is not a good choice.

Eventually, a simple workaround is just clone the repository again, and then copy the just downloaded .git or whole project folder to the existing project folder, so as to override the .git and source folder. Then it gets a clean git history and run git fetch or git pull --rebase will not cause any issue. 

May not be the best solution and definitely a working solution :)

Thursday, March 6, 2025

Javascript function to log the current method name and parameter

 It may be helpful to log the current method with some parameter without hardcode the method name for each log entry.  The below method can be used for this purpose


    logHelper(obj = {}) {
        var stack = new Error().stack,
        caller = stack.split('\n')[2].trim().substring(3);
        console.log(caller + ":" + JSON.stringify(obj));
     }

    someFunction(changes: SimpleChanges) {
        this.logHelper(changes);
// your business logic here
   }

Thursday, February 13, 2025

Why material UI css style not apply after angular and material version upgrade

Recently when upgrading angular and material UI version to 16 from lower vesion, somehow the css style does not apply correctly.

More investigation shows when upgrading to new material version, from some UI material component, the module was imported from legacy one instead of new material UI component, for example, the below code in app.module.ts, 


import { MatLegacyInputModule as MatInputModule } from '@angular/material/legacy-input';

import { MatLegacyProgressBarModule as MatProgressBarModule } from '@angular/material/legacy-progress-bar';


In order to fix the issue and get the expected UI look and feel, need to update the above code as below

import {MatInputModule} from '@angular/material/input';
import {MatProgressBarModule} from '@angular/material/progress-bar';

This should fix the css upgrading issue.

Tuesday, February 4, 2025

Using chrome developer tool to test css selector

 If you need to test css selector, you can use Chrome developer tool's console to do so.

For example, the below selector returns matched element id

document.querySelectorAll('#claimNumberInput')


you can also update UI to make it more visible

document.querySelectorAll('#claimNumberInput')[0].style.background=''red';

Tuesday, March 26, 2024

Difference between cluster, pod, container and node in Kubernete

Container is a place that a program can be deployed and executed, it has all the dependent runtime libraries. Docker is a good candidate to work as a container in order to hold a program and run from there. In jenkensfile, container is specified under containers section, each container in pad is specified with containerTemplate method. 

Pod contains one or more containers. Pods are smallest deployable unit in Kubernetes, all containers within a pod share the storage, network resource. In jenkinsfile, pod is represented with podTemplate method.

Cluster holds and manages pods, the pods within a cluster can be grouped based on namespace.

Node means the computer machines, either physical or virtual machines, that host the pods. In jenkins file, node is specified with node method, the label parameter specifies the node machine's name.

Monday, March 25, 2024

Understanding jenkinsfile, Dockerfile, and deployment YAML files

JenkinsFile is loaded and called by jenkins server for build and deployment. Ths code in this file will run in the default jnlp container.

The podTemplate method defined in Jenkins file specifies multiple container's with name and image id. Inside the podTemplate method, it can access git commit and branch info through scmInof.GIT_COMMIT and scmInof.GIT_BRANCH.

You can define multiple steps for build and deployment by calling stage method with their unique name, if a stage succeeds, it will run the next one. If a stage fails, it will abort the jenkins file execution. Within each stage method implementation, call container () method with name parameter to indicate which container should run the code, 

In one step, the stage method is called on nodejs container to build the project

In one following step, the stage method is called on docker container to build the docker image, which will use the Dockerfile, it then tags docker image, and push it to docker registration.

After the docker image is published, then a new stage method can run in kubectl container to apply the infrastructure yaml file defined for each deployment, within the deployment yaml file, it specifies the docker image id which is published in previous step, and create a new container image for its service.


Please refer to the below link for more details

https://www.jenkins.io/doc/pipeline/steps/kubernetes/