Creating a Web server using the Nodejs HTTP module
Contents 1.? Web Server Basics 2.? node. JS Web server 3.? Code implementation 1.?Web Server Basics
- Accept HTTP request (GET POST DELETE PUT PATCH HEAD)
- Handle HTTP requests (handle it yourself, or request other programs to process CGI)
- Respond (return pages, files, data, etc.)
Common Web server architectures:
- Nginx/apache: Responsible for accepting HTTP requests, determining who will process the request, and returning the result of the request
- php-fpm/php module: Processes the request assigned to itself and returns the processing result to the assigned person
Common request Type: request file: include static file (Web page picture js CSS), and program processing get the file to complete specific operation: Login to get specific data, etc.
2.?node. JS Web Server
- Do not rely on other specific Web server software (e.g. Apache Nginx IIS)
- node. JS code handles request logic
- The node. JS Code is responsible for the various configurations of the Web server (configuring Apache Nginx)
3.?Code implementation
var http= require ( http ' ); var RequestHandler = function (req,res) {//req request " Span style= "Color:maroon;" >hello );}; //Set callback method var web=http.createserver (RequestHandler); //began to listen for Web.listen (18000 ) Console.log (" http running on/HTTP localhost:18000 )
Use node file name to run
Source: https://www.madoko.net/preview/preview.html
From for notes (Wiz)
Creating a Web server using the Nodejs HTTP module