Core modules are introduced with require
Const HTTP = require ("http");
Create a server
Req: Requesting request
Req.url: The path to the current server's access
Req.method: How the current server is accessed
Res: Reply response
Res.end (): End response Reply last response reply
Res.write (): Reply response to the client
Res.statuscode: Server Status Code
Res.setheader (): Setting the response header
Res.writehead (); Shorthand for Res.setheader and Res.statuscode
Content-type:
Text/plain Plain Text
text/html html
Text/css CSS
image/* picture png
Application/x-javascript JS
Application/json JSON
Listen (): Binding port number
Example
Http.createserver ((req,res) =>{
Res.setheader ("Content-type", "Text/plain;charset=utf-8")
Res.statuscode = 308;
Res.writehead (200,{"Content-type": "Text/plain;charset=utf8"})
Res.write ("Wang more");
Res.write ("Hu Zhenyang");
Res.end ("Lei song");
}). Listen (9000)
Console.log ("Open please visit localhost:9000");
HTTP module of Nodejs core module