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,运行

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

 

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

 

使用VS Code调试NodeJs 工程代码

打开package.json

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

posted @   _成飞  阅读(117)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
点击右上角即可分享
微信分享提示