Nodejs Basic Method

Source: Internet
Author: User

node. JS is a platform built on the chrome JavaScript runtime to easily build fast, easy-to-scale Web applications. Node. js with event-driven, non-blocking I/O models become lightweight and efficient, ideal for data-intensive real-time running on distributed devices When applied
[2] node. JS is a platform that can quickly build Web services and applications. The platform was built based on the Chrome's JavaScript runtime, which means it was actually encapsulated by the Google V8 engine (applied to Google Chrome).
The V8 engine executes JavaScript very fast and performs very well. Node optimizes some of the special use cases, providing an alternative API that allows V8 to run better in a non-browser environment. [3]
For example, in a server environment, it is often necessary to process binary data, but JavaScript has insufficient support for this, so V8. Node adds the buffer class for easy and efficient processing of binary data. As a result, node does not simply use the V8, but also optimizes it to give it more power in every environment.
What are the features of node. js
1: Asynchronous IO
Asynchronous corresponds to unsynchronized, using asynchronous to allocate resources more highly
The vast majority of the operations in node are called asynchronously, and the node team has to build a lot of asynchronous IO APIs at the bottom, from file reads to network requests, in the sense that in node we can do parallel IO operations naturally from a language level, No extra wait between each call
For example, read two files, in a synchronous manner will be (Operation 1+ operation 2) Total time
And the async is Max (Operation 1+ Operation 2)
2: Event and callback function
Node chose Javascript,javascript not only to assume more responsibilities in the previous segment, but also to assume responsibility at the back end, which introduced a broad and mature time in the previous browser to the backend, with asynchronous IO exposing the point of time to the business logic
Case: node can create a server on the backend to handle requests sent by the user
In contrast, events are common in both the front and back ends
Event programming is a lightweight, loosely coupled, time-of-day focus, but in the context of multiple cross-field tasks, how time is independent and how cooperation will be a problem
The event callback in node is a feature of node, and he solves the problem that the callback function is the best way to accept the return data of an asynchronous call, (many older programmers can't accept it), that the code is written in a sequence that does not have much to do with the order of execution (which leads to a process control, not a good reading, So it is recommended to write the normal code as much as possible
3: Single Thread processing mode
Node keeps JavaScript in a single thread in the browser and doesn't enjoy any state in node, so don't worry about syncing.
But there's no way to avoid him, and he has his faults.
Unable to take advantage of multi-core CPUs
Generate errors will all exit the program
4: Cross-platform
Can be used on all platforms
Why Choose JavaScript
JavaScript since the birth of the location has been very awkward, before basically no one to think of it as a programming language (not many programmers will spend too much of their mind to learn) just as a web script, more applications are data validation (in fact, this is the first time to publish JS useful), But with the advent of the web2.0 era, JS has been in the page to play out more features, such as make your Web page more animated sense
In the web2.0 era, more of the former framework was developed by developers, initially only to solve the problem of incompatibility between browsers, such as jquery, but as more user needs in the previous break, JS from the previous application appeared in the development of application level above,
Tools (Browser compatibility)-Components (function Modules)-Framework (functional module organization)-Application (Application module organization)
Commonjs let JavaScript glow in the second spring, he let JS anywhere can run up
The weaknesses of JS itself
No module system
Less standard library-core library
Standard interfaces--such as database connections
Package management system-automatic loading and installation of dependent ask amount
Commonjs solves all of the above issues
Server-Side JS
Command-line tools
Desktop applications
COMMONJS Module Specification
Module Introduction
Require used to introduce modules
Module definition
The module represents the current block object
Exports export module

Nodejs Basic Method

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.