06-nodejs Introduction

Source: Internet
Author: User

Open Nodejs English Web: https://nodejs.org/en/

Chinese Web: http://nodejs.cn/

We will find this sentence:

Translate into Chinese as follows:

node. JS is a JAVASCRIPT runtime environment based on the Chrome V8 engine.
node. JS uses an event-driven, non-blocking I/O model to make it lightweight and efficient.
node. JS's Package Manager, NPM, is the world's largest open source library ecosystem.

Good. So before we introduce Nodejs, do we have a definition of javascript?

1.1 What is JavaScript?

Everyone who touches the front end knows that JavaScript is a scripting language that runs on the browser side and is used to interact with client pages.

What about the 1.2 javascript operating environment? So the name thinks that his operating environment is the browser, but is this really the case? In fact, his real operating environment is actually running in the browser kernel of the JS engine. Why is that so? Because of the popular browser is used to browse the Web, we in the browser in addition to the execution of JS can also carry out other things, such as we enter an address in the browser hit enter can send the request and receive the server response. So the first function of the browser is to request an HTTP address, that is, you can encapsulate a request message, the address of a URL encapsulated into a request message, the message to the server, then give us a response message, and then in the response to parse out, which is the browser's biggest role. Of course, the content of the server response may be different, for example, the server returned an HTML file, CSS files, img files, used to render, we call the rendering engine, in addition, can also execute JS, by the JS engine to complete, So it can be said that JavaScript is the operating environment of the browser JS engine, not the browser. The browser is a big concept. What can browsers do with JavaScript? 1.3 What JavaScript in the browser can do before it is mentioned, Javascrip is used to do the interaction, but generally speaking the interaction is a little unclear, the specific point can be divided into: "
???? (1) manipulating the DOM (that is, adding additions and deletions to the DOM, registering events, etc.)
???? (2) Sending AJAX requests/cross-domain
???? (3) BOM interaction such as to provide us with page jump, history, console print log
???? (4) ECMAScript (JS core language, such as to define variables, functions, etc.)
1.4, browser side of Javasscript can not do what????? Through the previous understanding, seemingly javascrip to our daily interaction can be completed, seemingly anything can be done, but he also has not to do. Such as:
???? (1) When it comes to end-to-end applications, we need to manipulate the files, JavaScript in the browser is not able to do the file operation, although the H5 provides the file-related APIs, but these APIs are mostly limited to the read-only level, not like traditional languages such as Java, by passing a path , and then read the corresponding file, it is plain that the file and folder can not be curd.
???? (2), browser-side JavaScript does not have the means to operate the operating system, such as obtaining the operating system version.
So why not do these two kinds of operations? In fact, because of security considerations, because, JS this language running environment is more special, said he special, special where? Although we have written a good JS code will eventually be placed on the server, but he is not executed on the server, but through the server sent to the browser to execute, the browser side of the operation of the file is obviously not safe, so that these functions in the client is not able to do, but because of the special operating environment can not do 1.5 , understand what the client JS can do, we must also clear a concept, that is, Javascrip can only run on the browser side????? Front-end developers know that Javascrip is composed of Ecmascrip language, Bom,dom, and at the language level, she just gives us some operational syntax, such as defining variables, functions, types, process controls, and so on. The bom,dom is provided by the browser and is not provided by ES. So the JS we often refer to is that most of Es,js's functions (Dom,bom (browser-open API) are determined by the browser's execution engine, which also derives an idea that any programming language, his ability is not determined by the language itself, It is determined by his enforcement environment. For example, Java, he is a language is also a platform, for JavaScript language is ES, platform is a browser. So JS can only run in the browser? Not too! For most languages, running on a single platform, such as Java only runs on virtual machines, but there are languages running on multiple platforms, Java at some level is not necessary to run on multiple platforms, because virtual machines are cross-platform (that is, cross-operating systems such as Windows, Linux, etc.). JS is also able to run on multiple platforms, the browser is able to run JS, because he is the execution of the JS engine. JS also, as long as supported by his platform can be executed. So to think that language has a very powerful function, only need to provide a powerful platform, node is such a platform to execute JS, then what is node exactly? Next, what's the Ghost of node?
What is node????? According to official documentation, node is a JavaScript runtime that gives Google V8 an engine that can be understood as a virtual machine running JS. He was using an event-driven, non-blocking I/O model, and he moved the JS environment to the server side, with no connection to the client. is a purely service-side thing, node just provides a platform for JS. Node inside actually divided two pieces, one is encapsulated the V8 engine, the purpose is to execute ES (such as defining variables, define functions, etc.), another provides a large number of tool libraries, is to help node to achieve a variety of functions, to provide some of the previous JS environment do not do things, such as file operations, network operations, Operation of the operating system.
???? Since node is a platform (the so-called platform is used to run a particular language), it means that node is used to run the language, then Java is the language, can node run Java? According to Nodejs founder Ryan Dahl, he initially chose the language of Ruby, but the efficiency of the virtual machine of the Ruby language is not very good finally give up, according to this idea, it seems that node will be Java Virtual Machine integration should be able to run Java, But the node author eventually chose JavaScript. This way JS can be implemented in the service side of the operation, JS running on node platform (divided into V8 section, used to execute ES, and a large number of tool library components (API) called LIBUV, providing the previous JS environment does not work, such as file operations, network operations, etc.).
Knowing what node is, you should also be aware of what node is used for in the web.
???? (1) node can accept all requests from client users and be able to respond quickly, so node can be used as a Web site.
???? (2) node can be used as a middle layer to distribute the call data interface, for example, there is a Web site data is provided by Java, we can let node as a middle, to accept the user's request, and then through node to invoke the Java data interface, After getting the data, make a bottle of HTML directly at the node level and then give the rendered page directly to the user. Why not just ask for the Java interface, because node is known as a high-performance Web server that is much better at concurrency and compression than traditional platforms, so this package can greatly reduce server development.
???? From the above two points, it can be concluded that node in the Web either from the front page to the back end of the full package of services, one is to do only one point.
???? Word, node is a JavaScript running environment (platform), he is not a language, nor is it the framework of JavaScript. Can be used to develop server-side applications, web systems. It is characterized by small size, fast and high performance.

06-nodejs Introduction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.