* * *\n\n## What is a Web Server?\n\nA Web server generally refers to a website server, which is a program residing on a certain type of computer on the Internet. The basic function of a Web server is to provide Web information browsing services. It only needs to support the HTTP protocol, HTML document format, and URL, working in conjunction with the client's web browser.\n\nMost web servers support server-side scripting languages (php, python, ruby, etc.), and retrieve data from databases through scripting languages, returning the results to the client browser.\n\nCurrently, the three most mainstream Web servers are Apache, Nginx, and IIS.\n\n* * *\n\n## Web Application Architecture\n\n\n\n* **Client** - The client, generally referring to the browser. The browser can request data from the server via the HTTP protocol.\n\n* **Server** - The server side, generally referring to the Web server, which can receive client requests and send response data back to the client.\n\n* **Business** - The business layer, which processes applications through the Web server, such as interacting with databases, performing logical operations, calling external programs, etc.\n\n* **Data** - The data layer, generally composed of databases.\n\n* * *\n\n## Creating a Web Server Using Node\n\nNode.js provides the http module, which is primarily used to build HTTP servers and clients. To use the HTTP server or client functionality, you must call the http module, the code is as follows:\n\nvar http = require('http');\nThe following demonstrates the most basic HTTP server architecture (using port 8080). Create a server.js file with the following code:\n\n## Example\n\nvar http = require('http'); var fs = require('fs'); var url = require('url'); http.createServer(function(request, response){var pathname = url.parse(request.url).pathname; console.log("Request for " + pathname + " received."); fs.readFile(pathname.substr(1), function(err, data){if(err){console.log(err); response.writeHead(404, {'Content-Type': 'text/html'}); }else{response.writeHead(200, {'Content-Type': 'text/html'}); response.write(data.toString()); }response.end(); }); }).listen(8080); console.log('Server running at http://127.0.0.1:8080/');\n\nNext, we create an index.html file in that directory with the following code:\n\n## index.html File\n\n
My First Title
My First Paragraph.
\n\nExecute the server.js file:\n\n$ node server.js Server running at http://127.0.0.1:8080/\nThen we open the address in the browser: **http://127.0.0.1:8080/index.html**, which displays as shown in the figure below:\n\n!(#)\n\nThe console output after executing server.js is as follows:\n\nServer running at http://127.0.0.1:8080/Request for /index.html received. # Client request information\n\n* * *\n\n## Creating a Web Client Using Node\n\nCreating a Web client using Node requires importing the http module. Create a client.js file with the following code:\n\n## Example\n\nvar http = require('http'); var options = {host: 'localhost', port: '8080', path: '/index.html'}; var callback = function(response){var body = ''; response.on('data', function(data){body += data; }); response.on('end', function(){console.log(body); }); }var req = http.request(options, callback); req.end();\n\n**Open a new terminal**, execute the client.js file, and the output is as follows:\n\n$ node client.js
My First Title
My First Paragraph.
\nThe console output after executing server.js is as follows:\n\nServer running at http://127.0.0.1:8080/Request for /index.html received. # Client request information