current position:Home>About node JS server related concepts

About node JS server related concepts

2022-04-29 16:28:09pigman

Server and client

A server is a machine that provides network services , By installing special software ( Or run a special piece of code ) To provide services .

Snipaste_2022-04-28_19-43-52.png
The server  = The computer + Can give other computers / The software that the device provides services
Client and server : The service is provided by the server , It is the client that enjoys the service

The type of server

Depending on the service , The types of servers are also different :

  • web The server . install apache, tomcat, iis, Or in nodejs Environment write code To provide : Picture view , News browsing .... And so on .
  • ftp The server . install serv-U Software , Provide file downloads for other computers , Shared services .
  • database server . install mysql Software , Provide database services for other computers . ....

web The server :

  • Users enjoy... Through the browser web Services provided by the server
  • We use it url Address To access a web Resources on the server
  • The browser initiates a request ,web After the server receives the request , In response to this request , And return the result to the browser

Snipaste_2022-04-28_19-51-23.png

ip Address

Full name :internet protocol address effect : Mark a network device , If you want to visit him, you have to find his ip
classification :ipV4   ipV6
Format :[0-255].[0-255].[0-255].[0-255] There are four 0-255 The numbers make up ( With ip4 For example ). In the same network , The computer IP It's not allowed to be the same , It's all unique .

domain name

domain name :ip The alias of the address , because ip Bad address memory , Just give them an alias .localhost This domain name refers specifically to 127.0.0.1 This address . Domain name resolution system : Translate the domain name into Ip Address system .

port

One IP The port of the address can have 65536 individual , Range is from [0,65535]). Different ports are occupied by different software , To provide different services . Multiple servers can be used to install software , such as Web service 、FTP service 、SMTP Service etc. . obviously , Just passed ip Addresses cannot distinguish between different services .

  1. To provide services, the server must pass Specified port
  2. Both the server and the client need to communicate through the port
  3. Ports are programmable
  4. Some port numbers are reserved .
  • http: 80
  • https:443
  • mysql:3306

use http Module write a simple web The server

// 1.  introduce http modular 
const http = require('http');

// 2.  Create services 
const server = http.createServer(function (request, response) {
  console.log(' Here we are ')
  //  Send content to the client 
  res.end('123321');
});
// 3.  Start the service 
server.listen(8000, function () {
  console.log(' Start the server ');
});
 Copy code 

Start the server first

Snipaste_2022-04-28_20-15-33.png Then enter the port , The effect is as follows

Snipaste_2022-04-28_20-12-24.png

copyright notice
author[pigman],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/04/202204291628045410.html

Random recommended