1. What is Nodejs?
Simply put, node. JS is the JavaScript that runs on the server.
node. JS is a platform built on the Chrome JavaScript runtime.
node. JS is an event-driven I/O server-side JavaScript environment, based on the Google V8 engine, the V8 engine executes JavaScript very quickly and with great performance.
2, why appear, solve what problem?
Traditional servers, such as PHP or Java, each Web HTTP request will produce a thread, assuming that each thread requires 2m of memory consumption, then a 8g server can only withstand 4,000 concurrent user requests, when the server cannot afford to add the server, This increases operating costs (of course, there is now nginx support, which can provide higher concurrent requests).
Fixed cost issues with long links and multiple requests.
Advantages: can handle high concurrent requests, save server resources.
3. Installation
https://nodejs.org/en/download/
windows, download the corresponding package and install it next.
Installation also installs NPM Package Manager
Node-v detection version and whether the installation was successful
4. Module Concept NPM
Modularity, a package that has a separate function of JS based on the CMD or AMD specification, is called a module.
Official explanation:
Modularity refers to the systematic decomposition of a problem in order to solve a complex problem or a series of mixed problems, according to a sort of thinking. Modularity is a way of dealing with complex systems that break down into manageable modules that are more logical and maintainable in code structures. Imagine a huge system code, how meaningful it is for software to be integrated and optimized to be segmented into highly logical modules. For the software industry: decoupling the complexity of the software system, so that no matter how large the system, but also can be management, development, maintenance to become "rational to follow"
Example: Desktop by: motherboard, CPU, memory, hard disk, monitor, mouse and other components, when we are not enough hard disk, plus, a component broken, change. It's very convenient. This is the embodiment of modularity. On the other hand: mobile phone, the CPU is bad, very troublesome, there may be the entire cell phone waste, although can also be changed, but the cost is high, this is the cost of non-modular.
Subsection (simplification of the complex, the small size of the large)
5. COMMONJS Specification
History 1:
JS since the birth, once no one took him as a real programming language, thought it is only a small script, in the web1.0 era, this scripting language widely circulated, one is form verification, the other is the web effect, due to be Bledenaik in a night black wind high moment in the development of the hastily, so there are many defects. To the Web 2.0 era, the front-end use of it greatly enhance the user experience of the Web page b/S application more and more widely, at this point, JS is valued. He has gone through the evolution of tools libraries, component libraries, front-end frameworks, and front-end applications.
History 2:
After a long day of hard work, JS constantly be clustering and abstract, to better organize business logic, a variety of encapsulation, all kinds of pseudo-inheritance, you look at others Java import, PHP includ, think of their poor, as a JS incredibly can not easily use on a JS or his brother, sad , can only be introduced in the browser with script tags, introduced more than both cause performance problems, but also caused poor maintainability, so the COMMJS specification was born, just like the birth of the Internet, The Times made heroes.
The COMMONJS specification provides a good vision for JS, hopefully it can run anywhere.
Commonjs defined module is divided into: {Module reference (require)} {module definition (exports)} {module identification (modules)}
Require () is used to introduce external modules; The exports object is used to export the method or variable of the current module, the only export, and the module object represents the modules themselves.
From for notes (Wiz)
1-1 Node Basics