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 .

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


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 This address . Domain name resolution system : Translate the domain name into Ip Address system .


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 
// 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


copyright notice
author[pigman],Please bring the original link to reprint, thank you.

Random recommended