About node. JS: 5 points that all PHP developers should know

Source: Internet
Author: User
Tags drupal

1. node. JS is built on Chrome's JavaScript Engine

We know that Google's Chrome browser has a very fast JavaScript Engine called V8. This JS engine can be isolated. Node. JS is built on V8. This is why node. js runs so fast. This has several advantages for developers:

  • You don't need to learn a new language. It is Js. I often view chrome and Mozilla's Js documents, which are completely common.
  • Benefiting from V8's JIT (Just In Time) compilation function, node. js applications run at a speed comparable to local code. Comparison tests show that node. JS is much faster than PHP and Ruby.
  • With the advancement of V8, node. js will also benefit.

2. node. JS is not just a web server or platform

Unlike PHP, node. JS is not webpage-centric. Node. JS is a general purpose JS runtime with a powerful library with many functions. One Library provides HTTP/HTTPS implementation.

You can use node. js to do many things. You can easily use it to create a command line program or other TCP/IP Services.

3. node. JS is object-oriented (similar to the eccentric JavaScript object-oriented style)

I like jquery. However, it made me become lazy and wrote a lot of simple, fast, but unsightly structured scripts. This is not a bad thing, because it is enough to handle simple web page behaviors. However, node. JS is not just used to handle the browser, but can be used to build applications, that is, you must consider the program architecture. When you use node. js to write code, you will go deep into the JS object model. I used to hate JS object models and often drive me crazy. However, node. js and NPM (node
Package Manager) makes good use of the JS prototype system, helps me understand many obstacles in class/interface usage, and makes me fall in love with object-oriented JS programming.

4. Event-based I/O

This is the most controversial aspect of node. js. Node itself runs in a thread. Yes, there is only one! You can compare it with a bunch of traditional Apache/PHP instances. However, node runs fast and efficiently.

How is this done? Share the execution time and place intensive IP address processing in other threads for processing. I can write a long article to discuss the advantages and disadvantages of this point, but here I want to say something practical: When you use node. when writing code in JS, you need to consider whether your task is slow or I/O-intensive. The asynchronous method is used to process callback or the event processor is used to process slow tasks.
Most importantly, you must ensure that the Code does not allow a request to occupy too long events on the node's main thread and does not give other requests a chance to process them.

5. package management is required!

Honestly, do you like pear? Do you convert most of your code into pear or PECL packages? Not many PHP programmers do this, and even many people do not know the existence of pear. In the world of node. JS, you must package the Code:

  • The Design of node. JS is a streamlined framework. 90% of the PHP core won't appear in the node. js core. For example, database drivers, email sending libraries, HTML support, and so on are not in the core library.
  • The core of node. JS is a modular framework. You will find it useful!
  • Node package manager is a required tool. With it, you can download various code packages, drivers, parsers, editors, and servers of node. js.
  • It is very easy to create and release your code package. I released my first code package shortly after using node.

If you are a Drupal developer, you will feel that the node package management system is a bit like a Drupal module. The difference is that you are facing developers rather than website builders.

Finally, is node. js suitable for you?

I mentioned many node. js features above, which I think should be known as PHP developers. The tone of this article also tends to be positive. Node is an interesting product with elegant structure. But node is not a panacea. I don't think node can replace PHP immediately. I just think PHP developers should learn about node. js. It is very simple and useful.

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.