首页 Node.js安装调试

VScode启动关闭服务器


新建文件:index.js
写入以下代码:
var http = require("http");   //加载http模块
http.createServer(function(req,res){  //监听8080端口
  res.writeHeader(200,{"Content-Type":"text/plain"});    //响应头信息
  res.end("hello World\n");  //响应内容
}).listen(8080,"127.0.0.1");
console.log("启动nodejs服务器");  //输出信息到控制台




启动VScode控制台:





启动node.js服务器:





打开浏览器:





关闭服务器:

单击一下VScode终端显示框,按组合键 CTRL + C