Nodejs Note 1

Source: Internet
Author: User

I used to use node to build a simple Weibo system. Recently, I need to repeat the node. After reading node, I had to be amazed at the js language. Although it is the power of the scripting language, it is not only indispensable for the front-end, but also can be achieved with js itself, in addition, its functions are far more than that, and more functions are being discovered. In addition, the emergence of node can be regarded as revolutionizing the traditional background server language. Unlike PHP, it also needs the support of Apache Web servers, so that it can pack and implement everything on its own. In many aspects of node, anonymous functions and callback functions are used. In short, an anonymous function has a name and only one function is used for guidance; a callback function is called by another party when a specific event or condition occurs and is used to respond to the event or condition, simply put, the function is passed as a variable. The HTTP server of node is simple but not simple. Here, an anonymous function is passed to the createServer function.

Var http = require ("http"); http. createServer (function (request, response) {response. writeHead (200, {"Content-Type": "text/plain"}); response. write ("Hello World"); response. end ();}). listen (0, 8888 );

 

Node is event-driven. The core of node is event-based programming. However, node is single-threaded. Unlike php, Apache automatically allocates processes when new requests enter. The createServer function listens to the port and also responds to the request. Obviously, this is asynchronous. However, this is where js event-driven principles play a role. In a word, node is an event-driven Asynchronous Server-side JS, And the callback function is an important principle for its implementation.

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.