Skip to content

How do debug nodejs language using dap mode

Ivan Yonchovski edited this page Feb 12, 2020 · 3 revisions
  1. Find the command that nodejs uses to run the language server:

For example, for docker-langserver I checked the content of docker-langserver which points to /usr/lib/node_modules/dockerfile-language-server-nodejs/bin/docker-langserver which has runs /usr/lib/node_modules/dockerfile-language-server-nodejs/lib/server.js. So the command that runs when you do docker-langserver is node /usr/lib/node_modules/dockerfile-language-server-nodejs/lib/server.js.

  1. Alter that command to add --inspect flag.
(setq lsp-dockerfile-language-server-command
      '("node" "--inspect=localhost:3000" "/usr/lib/node_modules/dockerfile-language-server-nodejs/lib/server.js" "--stdio" ))

Note: some of the server commands have to be set before lsp-mode has started or you have to evaluate the lsp-clients.el.

  1. Restart the language server and verify that it has started with the proper flags by doing M-x list-processes.
  2. After you have configured dap-mode according to dap-mode readme do:
(require 'dap-node)

(dap-debug
 (list :type "node"
       :request "attach"
       :port 3000
       :program "__ignored"
       :name "Debug docker language server."))
  1. Do M-x dap-ui-sessions and verify that you have attached to the language server.
  2. Do M-x dapui-loaded-sources to see which are the loaded sources in which you can set breakpoints.

Screenshot:

debug nodejs