NODEJS(8)Book Read - Nodejs_InfoQ.pdf
1. Introduce Platform
Node.js is not JS, it is platform based on V8 C++.
Node.js is event driven, callback. Net modules including HTTP, DNS, NET, UDP, HTTPS, TLS.
Node.js is single thread, sing process.
Javascript Closure
function(response) {
var responseHTML = “”;
response.on(‘data’, function (chunk) {
responseHTML = responseHTML + chunk;
});
response.on(‘end’, function() {
console.log(responseHTML);
}
}
a. call the inner properties in inner functions
b, keep all the properties in memory
2. What I installed on my Machine
>node -v
v0.10.28 >$ npm -v 1.4.10
Check the version of some mdules
>npm info express version
4.3.0
3. Module Strategy
var circle = require('./sillycat-aes/app/index');
console.log(circle.area(4));
var PI = Math.PI;
exports.area = function(r) {
return PI * r * r;
};
exports.circumference = function(r){
return 2*PI *r;
};
main in the package.json configuration.
4. Multiple Events in the same Time
api.getUser(“username”, function(profile) {
//got the profile
});
api.getTimeline(“username”, function(timeline){});
api.getSkin(“username”, function(skin){});
A plugin to fix the callback order/full problems
https://github.com/JacksonTian/eventproxy
5. Async
Check Status : read, select, poll, epoll, select, kqueue
Linux System provide AIO as async IO.
Node.js ——> libUV ——> linux (libev, libeio)
6. Buffer
var rs = fs.createReadStream(’testdata.md’, {encoding:’utf-8’, bufferSize:11});
data = data + trunk; ——> data = data.toString() + trunk.toString();
>npm info bufferhelper version
References:
Node.js_InfoQ.pdf
http://www.ruanyifeng.com/blog/2009/08/learning_javascript_closures.html
https://github.com/JacksonTian/eventproxy