Day: June 17, 2016

Node.js: 深入浅出Nodejs读书笔记

今天终于把朴灵老师写的《深入浅出Node.js》给学习完了, 这本书不是一本简单的Node入门书籍,它没有停留在Node介绍或者框架、库的使用层面上,而是从不同的视角来揭示Node自己内在的特点和结构。建议 有一定Node基础或者做过Node方面的小项目的同学阅读,看完以后你的思维会有很奇特的碰撞,我看的时候就常常会有这样的想法:“哦,原来这个功能是 这样实现的哦”。下面这篇文章是我第二次阅读《深入浅出Node.js》的一些学习记录,并且通过百度脑图这个工具来画出思维导图,每天将自己的学习总结写在这篇文章下面。图片文字太小可以右键从新标签页打开图片,然后点击就可以放大显示。 新增原始文件脑图地址,这样… Read More

Node.js: exports 和 module.exports 的区别

我理解的exports 和 module.exports 的区别,欢迎大家吐槽~ 为了更好的理解 exports 和 module.exports 的关系,我们先来补点 js 基础。示例: app.js var a = {name: 'nswbmw 1'}; var b = a; console.log(a); console.log(b); b.name = 'nswbmw 2'; console.log(a); console.log(b); var b = {name: 'nswbmw 3'}; console.log(a); console.log(b); 运行 app.js 结果为: D:\>node app { name: 'nswbmw 1' } { name: 'nsw… Read More

Node.js: 认识流stream

流是Node.js中一个非常重要的概念, 也是Node.js之所以适用于I/O密集型场景的重要原因之一。 流是Node.js移动数据的方式,流可以是可读的和/或可写的。在Node.js中很多模块都使用到了流, 包括HTTP和fs模块,本文将用尽可能简单的方式为你介绍Node中流的概念。 流 Stream 事实上,流通常用于将程序连接在一起。流可以被读和写。被流连接在一起的程序通常很小,并且只专注于做一件事。 你可能经常在项目中使用Gulp来做项目的代码构建,那么在使用过程中,你很可能碰到过类似下面的错误。 错误大概是这样个的: stream.js:94 throw er; // Unhandled stream error… Read More

Node.js: fs.readFile/writeFile 和 fs.createReadStream/writeStream 区别

1. 先说说各自的用法: How do I read files in node.js? fs = require('fs'); fs.readFile(file, [encoding], [callback]); // file = (string) filepath of the file to read encoding is an optional parameter that specifies the type of encoding to read the file. Possible encodings are ‘ascii’, ‘utf8’, and ‘base64’. If no encoding i… Read More