Home Web Front-end JS Tutorial What can node.js do? A summary of the functions of node.js in a few minutes

What can node.js do? A summary of the functions of node.js in a few minutes

Sep 05, 2018 pm 02:11 PM
js node.js

This article mainly introduces the definition of node.js, as well as a summary of the role of node.js. I hope everyone can learn more, let's read this article together

First, let’s take a look at what node.js can do?

This is a more formal introduction to node

Node.js is a JavaScript running environment based on the Chrome V8 engine.

Node.js uses an event-driven, non-blocking I/O model, making it lightweight and efficient. (Event-driven: A strategy for decision-making during the event triggering process. Simply put, it is to follow the things that appear at the current point in time and call available resources to solve the things, so that things that continue to appear can be solved and prevent the accumulation of things)

Node.js’s package manager npm has become the world’s largest open source ecosystem. If you want to know more, come to PHP Chinese websitenode.js video tutorial

These are the definitions of nodejs, now look at the summary of the role of nodejs:

Node.js has several particularly significant advantages: fast, high performance, high development efficiency, and wide range of applications.

Others will usually tell you vaguely: node.js is non-blocking. Features such as event-driven I/O make it possible to build applications with high concurrency (Polling) and comet.

When you feel you still don’t quite understand after reading these explanations, I will help you understand node.js in a simple and crude way.

The process of the browser sending requests to the website has not changed much. When the browser sends a request to the website. The server receives the request and begins searching for the requested resource. If necessary, the server will also query the database and finally send the response results back to the browser.

However, in traditional web servers (such as Apache), each request will cause the server to create a new process to handle the request.

Later came Ajax. With Ajax, we don't have to request a complete new page every time. Instead, we only request part of the page information we need each time. This is obviously an improvement

. But if you want to build a social networking site like FriendFeed (a website similar to Renren to refresh your friends’ news), your friends will push new statuses at any time, and your news will be automatically refreshed in real time.

To achieve this requirement, we need to allow users to maintain an effective connection with the server. The simplest implementation method at present is to maintain long polling between the user and the server.

HTTP request is not a continuous connection. You request once, the server responds once, and then it’s over. Long polling is a technique that uses HTTP to simulate a persistent connection. Specifically, as long as the page is loaded, whether you need the server to respond to you or not, you will send an Ajax request to the server.

This request is different from the general Ajax request. The server will not directly return information to you, but it will wait until the server feels it is time to send you information, and then it will respond. For example, if your friend posts a new message, the server will send the new message to your browser as a response, and then your browser will refresh the page. After the browser receives the response and refreshes it, it sends a new request to the server. This request still will not be responded to immediately. So I started repeating the above steps. Using this method, the browser can always wait for a response. Although the above process still only involves non-persistent HTTP, we simulated a seemingly continuous connection state

Let's look at traditional servers (such as Apache). Every time a new user connects to your website, your server has to open a connection. Each connection requires a process, and these processes are idle most of the time (for example, waiting for your friend to send new news, waiting for the friend to finish sending the message before responding to the user. Or waiting for the database to return query results, etc.).

Although these processes are idle, they still occupy memory. This means that if the number of user connections increases to a certain scale, your server may run out of memory and collapse.

How to solve this situation? The solution is what was just mentioned above: non-blocking and event-driven. These concepts are actually not that difficult to understand in the scenario we are talking about.

You think of a non-blocking server as a loop, and this loop will keep running. When a new request comes, this loop receives the request, passes the request to other processes (such as a process that performs database queries), and then responds with a callback. When it's done, the loop will continue to run and receive other requests. Come down like this. The server will not wait for the database to return results as before.

If the database returns the result, the loop will return the result to the user's browser and continue running. This way, your server's processes won't be waiting idle. Therefore, in theory, there is no limit to the number of database queries and user requests at the same time. The server only responds when an event occurs on the user's side. This is event-driven.

FriendFeed uses the Python-based non-blocking framework Tornado (Zhihu also uses this framework) to implement the new news function mentioned above. However, Node.js is even better than the former.

Node.js applications are developed through javascript and then run directly on Google's abnormal V8 engine. With Node.js, you don't have to worry about the client's request running a piece of code in the server that can cause blocking. Because JavaScript itself is an event-driven scripting language. If you think about it, when you write JavaScript for the front end, you mostly deal with event processing and callback functions. JavaScript itself is a language tailored for event processing.

Node.js is still in its early stages. If you want to develop an application based on Node.js, you will probably need to write some very low-level code.

But the next generation of browsers will soon adopt WebSocket technology, and long polling will also disappear. In web development, technologies like Node.js are only going to become more and more important.

The above is the summary of this article about node.js. It is very detailed. I hope you can read more so that everyone can better understand node.js. Students who want to learn more can go to the PHP Chinese websiteNode.js Development ManualColumn

[Editor’s Recommendation]

How to customize fonts in css? Introduction to text font styles in html

#html How to use the base tag? Summary of usage of html base tag

The above is the detailed content of What can node.js do? A summary of the functions of node.js in a few minutes. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use JS and Baidu Maps to implement map pan function How to use JS and Baidu Maps to implement map pan function Nov 21, 2023 am 10:00 AM

How to use JS and Baidu Map to implement map pan function Baidu Map is a widely used map service platform, which is often used in web development to display geographical information, positioning and other functions. This article will introduce how to use JS and Baidu Map API to implement the map pan function, and provide specific code examples. 1. Preparation Before using Baidu Map API, you first need to apply for a developer account on Baidu Map Open Platform (http://lbsyun.baidu.com/) and create an application. Creation completed

Recommended: Excellent JS open source face detection and recognition project Recommended: Excellent JS open source face detection and recognition project Apr 03, 2024 am 11:55 AM

Face detection and recognition technology is already a relatively mature and widely used technology. Currently, the most widely used Internet application language is JS. Implementing face detection and recognition on the Web front-end has advantages and disadvantages compared to back-end face recognition. Advantages include reducing network interaction and real-time recognition, which greatly shortens user waiting time and improves user experience; disadvantages include: being limited by model size, the accuracy is also limited. How to use js to implement face detection on the web? In order to implement face recognition on the Web, you need to be familiar with related programming languages ​​and technologies, such as JavaScript, HTML, CSS, WebRTC, etc. At the same time, you also need to master relevant computer vision and artificial intelligence technologies. It is worth noting that due to the design of the Web side

How to create a stock candlestick chart using PHP and JS How to create a stock candlestick chart using PHP and JS Dec 17, 2023 am 08:08 AM

How to use PHP and JS to create a stock candle chart. A stock candle chart is a common technical analysis graphic in the stock market. It helps investors understand stocks more intuitively by drawing data such as the opening price, closing price, highest price and lowest price of the stock. price fluctuations. This article will teach you how to create stock candle charts using PHP and JS, with specific code examples. 1. Preparation Before starting, we need to prepare the following environment: 1. A server running PHP 2. A browser that supports HTML5 and Canvas 3

Essential tools for stock analysis: Learn the steps to draw candle charts with PHP and JS Essential tools for stock analysis: Learn the steps to draw candle charts with PHP and JS Dec 17, 2023 pm 06:55 PM

Essential tools for stock analysis: Learn the steps to draw candle charts in PHP and JS. Specific code examples are required. With the rapid development of the Internet and technology, stock trading has become one of the important ways for many investors. Stock analysis is an important part of investor decision-making, and candle charts are widely used in technical analysis. Learning how to draw candle charts using PHP and JS will provide investors with more intuitive information to help them make better decisions. A candlestick chart is a technical chart that displays stock prices in the form of candlesticks. It shows the stock price

How to use JS and Baidu Map to implement map click event processing function How to use JS and Baidu Map to implement map click event processing function Nov 21, 2023 am 11:11 AM

Overview of how to use JS and Baidu Maps to implement map click event processing: In web development, it is often necessary to use map functions to display geographical location and geographical information. Click event processing on the map is a commonly used and important part of the map function. This article will introduce how to use JS and Baidu Map API to implement the click event processing function of the map, and give specific code examples. Steps: Import the API file of Baidu Map. First, import the file of Baidu Map API in the HTML file. This can be achieved through the following code:

How to use JS and Baidu Maps to implement map heat map function How to use JS and Baidu Maps to implement map heat map function Nov 21, 2023 am 09:33 AM

How to use JS and Baidu Maps to implement the map heat map function Introduction: With the rapid development of the Internet and mobile devices, maps have become a common application scenario. As a visual display method, heat maps can help us understand the distribution of data more intuitively. This article will introduce how to use JS and Baidu Map API to implement the map heat map function, and provide specific code examples. Preparation work: Before starting, you need to prepare the following items: a Baidu developer account, create an application, and obtain the corresponding AP

PHP and JS Development Tips: Master the Method of Drawing Stock Candle Charts PHP and JS Development Tips: Master the Method of Drawing Stock Candle Charts Dec 18, 2023 pm 03:39 PM

With the rapid development of Internet finance, stock investment has become the choice of more and more people. In stock trading, candle charts are a commonly used technical analysis method. It can show the changing trend of stock prices and help investors make more accurate decisions. This article will introduce the development skills of PHP and JS, lead readers to understand how to draw stock candle charts, and provide specific code examples. 1. Understanding Stock Candle Charts Before introducing how to draw stock candle charts, we first need to understand what a candle chart is. Candlestick charts were developed by the Japanese

The relationship between js and vue The relationship between js and vue Mar 11, 2024 pm 05:21 PM

The relationship between js and vue: 1. JS as the cornerstone of Web development; 2. The rise of Vue.js as a front-end framework; 3. The complementary relationship between JS and Vue; 4. The practical application of JS and Vue.

See all articles