vscode远程调试Node程序的示例
这篇文章主要介绍vscode远程调试Node程序的示例,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
目前创新互联建站已为千余家的企业提供了网站建设、域名、雅安服务器托管、成都网站托管、企业网站设计、建邺网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。
远程环境配置
首先要在远程服务器中打开SSH server功能,ubuntu系统基本都自带,没有的话,安装一下
apt-get install openssh-server
本地安装vscode插件
下载 VScode Insider版本,然后安装Remote Development扩展,安装 Remote Development扩展后,其它的Remote-SSH会自动安装,若不自动安装,请手动按照截图安装。

配置用户名/密码认证, 需要编辑一下VSCode的settings.json文件,打开的方式如下图,点击setting,点击任意一个‘Edit in settings.json’。

然后在settings.json 添加 "remote.SSH.showLoginTerminal": true

点击左下角的“open a remote window”,选择 ‘connect to Host’


根据图片顺序打开config文件,并填写远程主机的Host和登录名

弹出一个新窗口,根据提示,输入linux的密码

已经连接上了以后 ,点击 文件->打开文件夹(或者文件),可以显示出linux的文件夹(或者文件)

配置公钥
上面的步骤每次都要输入密码,非常麻烦,可以通过配置公钥来解决这个问题。
1、打开Git的安装目录,把 Git\usr\bin 放到环境变量。
2、然后打开过程 编辑主机config文件的目录 C:\Users\ye\.ssh (不同的电脑user名字会不一样),执行 ssh-keygen。
路回车即可! 完成后多了id_rsa,id_rsa.pub两个文件.
3、我们需要将id_rsa.pub 文件,复制一份到linux服务器上~/.ssh/目录下。若没有该目录,请执行mkdir ~/.ssh创建,然后将id_rsa.pub,远程传输到该目录下.
4、然后切换到该目录下,执行 cat id_rsa.pub >> authorized_keys,
5、修改 /etc/ssh/sshd_config文件下的
PubkeyAuthentication yes
,
AuthorizedKeysFile .ssh/authorized_keys .ssh/authorized_keys2
,两条是不是正常,若有注释,请取消,若不相同,请修改或者添加

6、重启远程主机的ssh服务 /etc/init.d/ssh resart
7、然后回到Windows的命令行,执行ssh (用户名)@192.168.160.132
括号中的请替换为您的Linux用户名,请一定要按照这种格式登陆,一定要输入用户名和IP,不要只输IP

此时打开文件的时候就不会再提示输入密码了
远程调试
找到远程服务器中 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" // 就增加这行 } ] }
以上是“vscode远程调试Node程序的示例”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联行业资讯频道!
文章题目:vscode远程调试Node程序的示例
文章链接:http://azwzsj.com/article/psgopc.html