Just read a small example in the node. JS document, which is a small example of writing a Web server with node. js
On the code (*^▽^*)
Helloworld.js
Use node. js to write a server Const http=require (' HTTP '); const hostname= ' 127.0.0.1 ' const PORT=3000;CONST Server = Http.createserver (req,res) =>{ res.statuscode=200; Res.setheader (' Content-type ', ' text/plain '); Res.end (' Hello world\n ');}); Server.listen (Port,hostname, () =>{ console.log (' server running in http://${hostname}:${port}/');});
Then in the console input node Helloworld.js, and then the console display server run address copied to the browser, if you can see Hello world indicates that the server is running successfully (-^) V
Feel this piece of code encapsulation is very tight, logic is clear, but do not know how to use (?_?), later learned to update it (*^▽^*)
Write a Web server using the methods in the node. JS Document