Native mode construction

Recently, I was writing an Ajax case that needed the support of the backend, so I learned about Node.jsCopy the code

Simple test: Create a new sever. Js file under the current project and write the following to it:

// Import the HTTP module
var http = require('http');
http.createServer(function (req,res){
    // Set the encoding
    res.write("<head><meta charset='utf-8'></head>")
    // Set the response body
    res.write("Node server setup successfully")
    / / end
    res.end()
}).listen(3000) // Set the port number
Copy the code

Next is the most critical step. Open Windows terminal, CD to the current file, and execute the following command

node sever.js
Copy the code

The normal situation is as follows:Then open your browser and type in the address barhttp://localhost:3000/, the correct case is as follows: