Minikube - Debug NodeJS app

12/12/2016

I am running minikube on my mac for developing/testing my micro-services locally. I was wondering if it is possible to debug my NodeJS in minikube via node-inspector? (other tools are also welcome). I saw that there is an option to use node-inspector using docker-compose but since i am running all my services in k8s i choose Minikube.

Thanks in advanced!

-- Ran Hassid
kubernetes
minikube
node-inspector
node.js

1 Answer

12/15/2016

Say you have this npm script:

"dev": "concurrently -p \"[{name}]\" -n \"NODE INSPECTOR,NODEMON\" -c \"bgBlue.bold,bgGreen.bold\" \"node-inspector --web-port=8081 --debug-port=5860 --preload\" \"cross-env NODE_ENV=development nodemon ./node_modules/babel-cli/bin/babel-node.js --max-old-space-size=512 --debug=5860 ./index.js\""

node-inspector is not running on port 8081.

Now in your kubernetes.yml you could have the following:

---

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    app: helloworld
  name: helloworld
  namespace: application
spec:
  replicas: 1
  selector:
    matchLabels:
      app: helloworld
  template:
    metadata:
      labels:
        app: helloworld
    spec:
      containers:
      - name: helloworld
        imagePullPolicy: Always
        image: fbgrecojr/hello-world:latest
        ports:
        - containerPort: 8080
          protocol: TCP
        - containerPort: 8081
          protocol: TCP

---

kind: Service
apiVersion: v1
metadata:
  labels:
    app: helloworld
  name: helloworld
  namespace: application
spec:
  type: NodePort
  ports:
  - port: 8080
    protocol: TCP
    nodePort: 30000
  - port: 8081
    protocol: TCP
    nodePort: 30001
  selector:
    app: helloworld

your app is not accessible from $(minikube ip):30000 and node inspector is available from $(minikube ip):30000

-- frankgreco
Source: StackOverflow