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 }`)
  })

posted @ 2019-08-14 17:28  豆芽菜小院  阅读(123)  评论(0)    收藏  举报