- 创建
server.js
文件// 1. 导入http模块 let http = require('http') // 2. 创建服务器并返回数据hello world http.createServer(function(request,response){ // 发送 HTTP 头部 // HTTP 状态值: 200 : OK // 内容类型: text/plain response.writeHead(200,{'Content-type':"text/plain"}) // 发送响应数据 “hello world” response.end('hello world') }).listen(8888) // 设置端口号为 8888
- 开启终端,
cd
到server.js
文件所在目录 - 运行
node server.js
命令,通过浏览器访问http://127.0.0.1:8888/
就可以看见页面中输入了hello world
Node学习笔记(二)—— 建立简单服务器
猜你喜欢
转载自blog.csdn.net/weixin_44876003/article/details/104767974
今日推荐
周排行