In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
What is nodejs? I believe many inexperienced people are at a loss about it. Therefore, this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
Nodejs is a JavaScript running environment based on Chrome V8 engine, a development platform that allows JavaScript to run on the server side, and a scripting language JavaScript as a server language. The advantages of node: high concurrency ability, using JavaScript syntax, etc.
The operating environment of this tutorial: windows7 system, nodejs 14.15.4, DELL G3 computer.
Node.js was released in May 2009 and developed by Ryan Dahl. It is a JavaScript runtime environment based on Chrome V8 engine. It uses an event-driven, non-blocking I-peg O model to let JavaScript run on the server-side development platform. It makes JavaScript a scripting language on a par with PHP, Python, Perl, Ruby and other server-side languages.
Node.js optimizes some special use cases and provides alternative API to make V8 run better in non-browser environment. V8 engine executes Javascript very fast and has very good performance. The platform based on Chrome JavaScript runtime is used to build web applications with fast response and easy to expand.
Node.js uses the Google V8 JavaScript engine because:
V8 is open source software based on BSD license
V8 is very fast.
V8 focuses on network functions and is more mature in HTTP, DNS, TCP, etc.
What are the advantages of Node.js? Why can scripting language JavaScript be used as a server language?
Advantage 1 Node.js has super high concurrency ability
The initial goal of Node.js is to provide a simple development tool for creating high-performance servers and running various applications on the server.
Compared with classic server-side languages such as Java,PHP or. Net, Node.js is like a young man. Java language creates a new thread for each client, while each client connection creates a thread that consumes 2MB memory. In other words. In theory, a 8GB server can connect about 4000 users at the same time. If there is a high concurrency to support more users, it is necessary to add additional servers.
Node.js does not create a new thread for each customer connection, but uses only one thread.
This is why Node is based on a single thread (only one main thread picks up the request and gives the response)
Isn't that slower? In fact, this is not the case.
When Node.js receives a user connection, it triggers an internal event. It responds to the user's behavior through pre-defined functions. The Node.js main thread does not care about the flow of the program. In fact, there are other worker threads to help the Node main thread to access files and read the database. When the worker thread reads the file data, or the data in the database, it will return the callback function to the Node main thread to execute, such as sending the found data back to the client and closing the connection. (this is Node non-blocking Istroke O, based on event-driven).
A picture I drew is attached below (please see me if there is any inappropriateness)
At this time, we should have an embryonic form in our heads, that is, the Node.js main thread has been busy receiving and responding to requests, so that it can constantly receive requests from multiple clients. It does not have to wait for the IO operation. When the IO worker thread finds the data, it will trigger the event callback function to tell the main thread that the data has been obtained. At this time, the main thread executes the callback function. Return the data to the client.
In theory, a server with 8 gigabytes of memory can hold 30 to 40, 000 connections at the same time.
This is the highlight of Node (single-threaded, non-blocking IO, event-driven)
Advantage 2 Node uses the syntax of JavaScript
Node.JS is based on javaScript's V8 engine, which means that as long as you know the syntax of JS, it can be used for back-end development, but Node officially recommends ECMA Script6 (ES6) syntax.
Node breaks the situation that JavaScript can only run in browsers in the past, and unifies the front and back end programming environment, which greatly reduces the development cost. (this is very friendly to front-end developers. JS can do more and more things, and the front-end development is getting faster and faster.)
Advantage 3 the emergence of Node.JS promotes the idea of front-end engineering
The front-end has developed rapidly in recent years, and Node.js plays an irreplaceable role.
Node.js is not only a running environment, but also a completely new JavaScript language, which contains the basis of JS syntax and adds some internal modules.
Such as:
The module used by http to process request response
The module used by fs to read files
Url is used to parse request data and so on.
Const http = require ('http')
Node.js also integrates Npm package management tools, so that we can easily download packages that our project depends on from the command line.
Such as:
Npm install jquery
Npm install-g webpack
Npm install-g create-react-app, etc.
Similarly, it can be used as long as it is introduced into the project.
Const Jquery = require ('jquery')
Node also supports custom module syntax ↓↓
Const app = () = > {/ / Module Code} module.exports = app;const app = require ('module/app.js'); / / introduce a custom module
Node.js affects the pattern of front-end development in some way. Make the front-end engineering modular, develop quickly, reduce the code coupling, and greatly enhance the maintainability.
What is suitable for Node.js?
Here are a few Node.js application scenarios
After reading the above, have you mastered what is the method of nodejs? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.