一、服务器区别
- 对于其他的后端语言,比如php,wamp(apache—+mysql),java(tomcat)都有自己提供的服务器
- node.js需要手写
二、书写语法
//1.引入http模块
const http=require('http')
//2. 创建服务
const server=http.createServer()
//3. 监听请求
server.on('request',(req,res)=>{
res.end('hello bfy') //客户端给用户返回的数据
})
//4.监听端口号 listen(port,ip,callback)
server.listen(3000,function(){
console.log('node-server running at http:127.0.0.1:3000')
})
listen(port,ip,callback)三个参数:
- port:端口号
- ip:默认为1
- callback:回调,用于提示
三、根据不同请求返还不同数据
1.引入模块
const http=require('http')
const path=require(