3-04.原生代码创建服务器
原生代码创建服务器
const http = require( 'http' )
const port = 3000
const hostname = 'localhost' // 127.0.0.1
http.createServer((request,response) => {
response.writeHead( 200, {
'Content-Type': 'text/html;charset=utf8'
})
response.write('hello Node.js - 千锋教育')
response.end()
}).listen(port,hostname,() => {
// 参数: 端口 域名 监听回调
console.log(`The Server is running at: http://${ hostname }:${ port }`)
})

浙公网安备 33010602011771号