Windows 运行nodejs程序

创建第一个应用,首先任意目录新建一个txt。复制以下内容:

//引入required模块
var http = require("http");
//创建服务器
http.createServer(function(request,response){
    //发送头部
    response.writeHead(200,{'Content-Type':'text/plain'});
    //发送响应数据
    response.end('hello , world\n');
}).listen(8888);
 
//终端打印以下信息
console.log('Serve running at http://127.0.01:8888/');

保存,然后再重命名为helloworld.js,文件后缀名是.js。第一个node.js应用就创建完成了,然后打开cmd,运行

node D:\work\nodeJS\test\helloworld.js

 

如上图所示后,在浏览器访问http://127.0.0.1:8888,看到一个hello ,world的网页。

 

使用VS Code调试NodeJs 工程代码

打开package.json

 点击运行调试,即可进行程序的调试

posted @ 2023-12-18 12:17  _成飞  阅读(52)  评论(0编辑  收藏  举报