node. JS Summary 2

Source: Internet
Author: User

Download node Install NPM I won't say anything.

Introductory summary

Http://www.cnblogs.com/Darren_code/archive/2011/10/31/nodejs.html

Enter the Node_home directory

Test.js

/*var hello = require ('./hello.js '); Console.log (' hello.location: ' + hello.location ') console.log (' hello.location: ' + Hello.name) Hello.showlog ();*/    varFS = require ('FS'); Console.log (' One'); varHello = require ('./hello.js'); Console.log (' A'); Fs.readfile ('./hello.js', function (err, data) {if(ERR)Throwerr; Console.log ('successfully');  }); Console.log ('Async');varEvents = require ("Events"); varEmitter =Newevents.   Eventemitter (); Emitter.on ("MyEvent", Function (msg) {Console.log (msg);   }); Emitter.emit ("MyEvent","Hello World.");varFS = require ('FS'); Fs.unlink ('./hello.js', function (err) {if(ERR)Throwerr; Console.log ('successfully deleted Mymodule.js'); });

Hello.js

Console.log ('xx');       var " Darren "  ;   This"Beijing";  this. Showlog = function () {    console.log ('Hi Darren. ' )};

Output:

11
00
22
Async
Hello World.
Successfully deleted Mymodule.js
Successfully

Analysis of Basic concepts:

Module: In fact, the equivalent of a JS class, through the require (path) way to create and introduce a module

Asynchronous:

Node each built-in module and its API

Sys

Fs

http

Agent

wr.

Path

File

Events

http://nodejs.iteye.com/blog/1587019

In general, JS through the Eval assembly service end of the JSON string into a JS object-the server has another JSON interpreter

var AA = Json.parse ("{\" a\ ": \" C\ "}"); JSON is also built into JS

Server-side request processing of the browser is usually: each request to establish a thread ...?

Be sure to understand what the problem you need to solve, and take the best solution based on it, instead of solving the problem based on the skills you are currently mastering

Node's advantages:

Non-blocking (asynchronous),

High concurrency (asynchronous, event-based I/O)

Building Scalable Web Applications (single thread _ traditional Web server one request, multithreaded)

Very Good article:

Http://www.cnblogs.com/liusuqi/p/3735491.html

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.