Creating a Web server using the Nodejs HTTP module

Source: Internet
Author: User

Creating a Web server using the Nodejs HTTP module
[Email protected]
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.