//index.js
const http = require('http')
const server = http.createServer((req, res) => {
// req即request,res即response
//console.log('ok'); // 每次请求都会执行一次回调函数中的语句
// 浏览器输入的 url 为 http://localhost:2000/hello?username=sense&sex=male#hello,
// 则 req.url 为 /hello?username=sense&sex=male,
// 浏览器输入的 url 中的 hash(如上的 #hello)无法传递到后端
const url = req.url.split('?')[0]
res.end(url)
// 每次触发请求回调函数中只能调用一次response.end(),否则会报错
})
const port = 3000;
server.listen(port)
console.log('hello port '+ port);
#node index.js