Visual Studio Code搭建NodeJs的开发环境
1、下载安装NodeJs并配置环境变量
2、下载安装 VS Code编辑器
3、vscode配置nodejs调试环境
侧边栏 调试按钮 添加 nodejs 配置 launch.json
编写 launch.json 配置文件
// nodemon 配置 { "version": "0.2.0", "configurations": [ { "type": "node", "request": "launch", "name": "nodemon", "runtimeExecutable": "nodemon", "program": "${workspaceFolder}\\server\\bin\\www", "restart": true, "console": "integratedTerminal", "internalConsoleOptions": "neverOpen" } ] }
4、调试
创建Hello word Demo
创建测试服务器server.js
var http=require('http'); http.createServer(function(req,res){ res.writeHead(200,{'Content-Type':'text/plain'}); res.end('hello node.js'); }).listen(3000,'localhost',function(){ console.log('Server running at http://localhost:3000'); });
5、使用VS Code运行或调试代码说明
(1)、运行代码段(选中的代码),输出结果
(2)、运行js文件,启动服务器监听
(3)、结束nodejs的服务器监听
方式1:在任务栏管理器中结束nodejs对应的当前服务器的进程
方式2:在输出控制台,右键‘Stop Code Run’
以上就是vscode怎么配置nodejs?的详细内容,更多请关注0133技术站其它相关文章!