Use nodejs to make a website

my understanding is:

  1. Front-end page (such as an index.html)
  2. web server (such as apache)
  3. backend programs (such as writing one in java or php)

in my concept, the three are separate, but in nodejs, 2 and 3 seem to be together, and you can"t always find an introduction to this when querying information about nodejs.
wants to get some explanations of web server and back-end programs in nodejs
(for example, how to do web server use and back-end programs development, the relevant information is always very confusing)
add: specifically, suppose I need to implement

  1. access my index.html using ip
  2. how should the back-end program respond to a post request in index.html using nodejs

(no specific code implementation is required, just want to know how to implement it)

Mar.19,2021

layering, in fact, different schools have different divisions, depending on what kind of architecture you use. For example:

there are five divisions that correspond to different architectural patterns.
back to the topic, I think it is reasonable to divide it into "presentation layer", "control layer" and "application layer" (so I suggest you take a look at something about MVC). The reason why there is not a "website server" is because it depends on the website structure. If you have both front-end and back-end content, you can use the Web server to separate the requests. The front-end requests return static resources, and those involving the back-end are forwarded to the back-end application services for processing (but the back-end application services can also be handled by themselves, but the Web server may be lighter and more flexible). But if it is a pure back-end project, it does not need to be forwarded by the Web server, just use the back-end application service to monitor the request, and there is no such thing as a "website server".


the boss upstairs has talked a lot of theories. Let me add a direct and targeted answer.

  • A typical nodejs server does handle 2 and 3 together. If you have a professional background, the online course will use C/PP to write server homework, which is also handled by 2 and 3 together. From this point of view, nodejs actually feels a bit like going back to basics.
  • but nodejs can not deal with 2, but only 3. A typical scenario is that nginx+nodejs does load balancing. But at this time, nodejs is still logically independent, and it communicates with nginx through the standard HTTP protocol, not cgi.
  • traditional websites are divided in this way because when HTTP was first invented, most of the content was static, and many sites did not have an apache,3 at all. Sites that use nodejs are mostly dynamic, there is no point in separating routing and logic, and the configuration files are scattered.
< hr >

answer the supplementary question of the subject:

if you have done the homework of C/PP server, you will understand it very thoroughly
  1. complete the TCP handshake with the client
  2. client sends message
  3. nodejs receives message
  4. nodejs deserializes the request line to get the post in the request line
  5. nodejs hands the message body to the corresponding callback function
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e511e6-66aaa.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e511e6-66aaa.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?