Home  >  Article  >  Development Tools  >  Introduction to the method of remote debugging Node program with vscode

Introduction to the method of remote debugging Node program with vscode

青灯夜游
青灯夜游forward
2020-09-15 10:57:543441browse

Introduction to the method of remote debugging Node program with vscode

This article will introduce to you how to remotely debug Node programs with vscode. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

Video tutorial recommendation: vscode basic tutorialnode js tutorial

Remote environment configuration

First, open the SSH server function in the remote server. The ubuntu system is basically All come with it, if not, install it

apt-get install openssh-server

Local installation of vscode plug-in

Download the VScode Insider version, and then install the Remote Development extension. After installing the Remote Development extension, other Remote-SSH will automatically Installation, if it does not install automatically, please install it manually according to the screenshot.

Introduction to the method of remote debugging Node program with vscode

To configure username/password authentication, you need to edit the settings.json file of VSCode. The way to open it is as shown below. Click setting and click any one of 'Edit in settings.json'. '.

Introduction to the method of remote debugging Node program with vscode

Then add "remote.SSH.showLoginTerminal": true in settings.json

Introduction to the method of remote debugging Node program with vscode

Click " open a remote window", select 'connect to Host'

Introduction to the method of remote debugging Node program with vscode
Introduction to the method of remote debugging Node program with vscode
##Open config according to the order of the pictures file, and fill in the Host and login name of the remote host

Introduction to the method of remote debugging Node program with vscode
A new window will pop up. According to the prompts, enter the Linux password

Introduction to the method of remote debugging Node program with vscode##After being connected, click
File->Open Folder (or File)

to display the Linux folder (or file)

Introduction to the method of remote debugging Node program with vscodeConfiguring the public key

The above steps require you to enter the password every time, which is very troublesome. You can solve this problem by configuring the public key.

1. Open the Git installation directory and put Git\usr\bin into the environment variable.

2. Then open the process and edit the directory of the host config file C:\Users\ye\.ssh (the user name will be different on different computers), and execute ssh-keygen.

Just press Enter! After completion, there are two more files, id_rsa and id_rsa.pub.

3. We need Copy the id_rsa.pub file to the ~/.ssh/ directory on the Linux server. If there is no such directory, please execute mkdir ~/.ssh to create it, and then remotely transfer id_rsa.pub to the directory.

4. Then switch to the directory and execute cat id_rsa.pub >> ; authorized_keys,

5. Modify

PubkeyAuthentication yes

,

AuthorizedKeysFile .ssh/authorized_keys under the /etc/ssh/sshd_config file .ssh/authorized_keys2

, are the two items normal? If there are comments, please cancel them. If they are not the same, please modify or add

Introduction to the method of remote debugging Node program with vscode6. Restart the remote host. ssh service /etc/init.d/ssh resart

7. Then return to the Windows command line and execute ssh (user name)@192.168.160.132

Please replace the ones in the brackets with yours Linux username, please be sure to log in according to this format, be sure to enter the username and IP, do not just enter the IP

Introduction to the method of remote debugging Node program with vscode

此时打开文件的时候就不会再提示输入密码了

远程调试

找到远程服务器中 node 的路径

which node

在 launch.json 中添加配置

{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Launch Program",
      "program": "${workspaceFolder}/server/server.js",
      "runtimeExecutable": "/root/.nvm/versions/node/v8.6.0/bin/node" // 就增加这行
    }
  ]
}

更多编程相关知识,请访问:编程入门!!

The above is the detailed content of Introduction to the method of remote debugging Node program with vscode. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:zhihu.com. If there is any infringement, please contact admin@php.cn delete