About Node. js: 5 points for PHP developers

Source: Internet
Author: User
Tags drupal

I recently started to deal with Node. js. Previously I used PHP development, especially Drupal. I found it easy to transfer to Node. js and the process was pleasant! But I also need to learn to think from different angles. Below I list five Node. js features that I think PHP engineers should know.

 

Node. js Zone

1. Node. js is built on Chrome's JavaScript Engine

Google Chrome 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. For developers, there are several advantages:

◆ You do not 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. The comparison test shows that Node. js is much faster than PHP and Ruby.

◆ As V8 progresses, 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 (although ODD)

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. But Node. js and NPM (Node Package Manager) make good use of the JS prototype system, which 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 quickly 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!

◆ NPM (Node Package Manager) is a required tool. With it, you can download various Node. js Code packages, drivers, parsers, editors, servers, and so on.

◆ 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 the developer you are facing is not a builder.

Conclusion: ask your doctor if Node. js is suitable for you.

I mentioned the features of Node. js that many PHP developers should know. There are thousands of articles about Node. js on the Internet, most of which are positive. Node is an interesting product with an elegant architecture. 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.

Original article: http://www.oschina.net/news/25413/about-nodejs

Related Article

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.