Node.js using native code implementation static server

const http = require ( 'http'); // import module

const PORT = 3000; // set the port number 3000 (3,000,500,060,009,000)

const HOSTNAME='localhost'; //或"127.0.0.1"

 

http.createServer((req,res)=>{ 

  res.writeHead('Content-type:text/html,charset:utf-8');

  res.writeHead (200, {// set the response status code header !!!!!!!!!!!
  'Content-Type': 'text / html; charset = utf8' // character encoding 'Content-type': 'text / html; charset: utf8';
  })

  res.write('xxxxxxxx');

  res.end ( 'end xxx')

      

}).listen(PORT,HOSTNAME,()=>{

console.log(`The Server is running at: http://${ HOSTNAME }:${PORT}`)

  })

 

Guess you like

Origin www.cnblogs.com/zhangzhouy/p/11355753.html