node (web application)

//Import http module

const http = require('http')

// Declare a constant named port

const port = 3000

// Called the createServer method in the http module to create the server

// Two parameters: require (request, request content from the server)

// response (response, content from the server to the browser)

 const serve = http.createServer((require,response) =>{

//Set the response status code to 200

   response.statusCode = 200

//Set the response header

response.setHeader('Content-Type','text/plain;charset=UTF-8')

// Set the response body, the content that the server actually returns to the browser

response.end('hello world')

})

//start the server

serve.listen(port,() =>{

    console.log('The server is already running and the port number is: ${port}/');

})

 

 

 

Guess you like

Origin blog.csdn.net/m0_73495603/article/details/127756594