Great routine analysis of node. js Reading Notes _ node. js-js tutorial

Source: Internet
Author: User
This article mainly introduces the amazing node. the routine analysis of js Reading Notes. If you need it, you can refer to the nodejs learning content of the next week for the use of several dependent packages and repeat the examples in the book. This article takes the routine as a clue to review the work of the week.

1. connect

This routine mainly uses the connect dependency package. connect provides a middleware (composed of functions that interact with request and response objects) function. The book also introduces other built-in middleware of connect, which can organize code to complete web functions.

2. session

Use connect to perform user sessions and perform basic logon to the system. Middleware allows you to check logon, display forms, match users, and process logout. Demonstrate the strength and organization of middleware.

3. express-tweet

This chapter describes how to use the express package and connect-based express. The program design is still simple, but in different np versions, function names will change. For example, express. createServer () becomes express () after 3.0 (). The biggest benefit of using express is its simplicity and flexibility. However, if tweet cannot be accessed, but is rewritten as weibo, weibo's API access is too complicated. In fact, this program is not successfully run.

4. echo

The two routines use the WebSocket package. The echo function is to record the message transmission time. Websocket uses ws to listen to (on) an event and process it in the callback function. js is also used for message interaction in html files.

5. cursors

In this example, broadcast is learned. This function is processed by a self-written broadcast function. Make sure that the cursor element exists by dom id lookup.

6. chat

This chapter can be said to be the highlight of this book, because the Socket. IO package was developed by the author. It differs from WS in that its message transmission is based on transmission rather than WS. This routine first implements the chat function and then the broadcast Song (DJ) function. There were no major problems in the process. One process is a socket. emit event. The socket at the other end listens to the event and processes it.

7. Summary

This week's efficiency is quite good, and the problems encountered are still on evernote. The difference between localhost and 127.0.0.1 has also occurred before. This week, I learned a function during js debugging, which allows js to dump an object like php. Now paste it below for sharing.

The Code is as follows:


Function dump (arr, level ){
Var dumped_text = "";
If (! Level) level = 0;

// The padding given at the beginning of the line.
Var level_padding = "";
For (var j = 0; j
If (typeof (arr) = 'object') {// Array/Hashes/Objects
For (var item in arr ){
Var value = arr [item];

If (typeof (value) = 'object') {// If it is an array,
Dumped_text + = level_padding + "'" + item + "'... \ n ";
Dumped_text + = dump (value, level + 1 );
} Else {
Dumped_text + = level_padding + "'" + item + "' => \" "+ value +" \ "\ n ";
}
}
} Else {// Stings/Chars/Numbers etc.
Dumped_text = "==>" + arr + "<== (" + typeof (arr) + ")";
}
Return dumped_text;
}

I will start learning mongoDB in the next week.Learning routine, reading Source Code APITo improve. After all, the advantage of node is the np of a large part of the network.

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.