0
点赞
收藏
分享

微信扫一扫

NodeJS搭建简易服务器

// http.js
//引入内置http模块
var http = require("http")
// 创建服务器
var server = http.createServer(function(req,res){
    // //设置响应状态码,响应头(编码格式)
    res.writeHead(200, {"Content-Type" : "text/plain; charset=utf-8"});
   //  //设置响应内容
    res.write("hello node.js!");
   //  //结束响应
    res.end()
})

// 设置服务器端口
server.listen(3000)

在CMD命令窗口中切换到该服务器文件所在目录,然后 输入node http.js,回车!

打开浏览器,在地址栏输入localhost:3000,回车!


原文详解:https://www.cnblogs.com/saber200/p/5242732.html

举报

相关推荐

0 条评论