text: (window.webpackJsonp=window.webpackJsonp||[]).push([[25],{186:function(t,s,n){"use strict";n.r(s);var a=n(0),e=Object(a.a)({},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("div",{staticClass:"content"},[t._m(0),t._v(" "),t._m(1),t._v(" "),n("p",[t._v("总结起来node有以下几个特点:简单强大，轻量可扩展。")]),t._v(" "),t._m(2),t._v(" "),t._m(3),t._v(" "),t._m(4),t._v(" "),t._m(5),t._v(" "),t._m(6),t._v(" "),t._m(7),t._v(" "),t._m(8),t._v(" "),n("p",[t._v("总体上执行顺序是：process.nextTick >> setImmidate >> setTimeout/SetInterval"),n("br"),t._v(" "),n("a",{attrs:{href:"https://github.com/nodejs/node/blob/master/doc/topics/event-loop-timers-and-nexttick.md",target:"_blank",rel:"noopener noreferrer"}},[t._v("参考官方介绍"),n("OutboundLink")],1)]),t._v(" "),t._m(9),t._v(" "),n("p",[t._v("Buffer是用来处理二进制数据的，比如图片，mp3,数据库文件等.Buffer支持各种编码解码，二进制字符串互转．")]),t._v(" "),t._m(10),t._v(" "),n("p"),t._v(" "),t._m(11),t._v(" "),t._m(12),t._m(13),t._v(" "),n("p",[t._v("代码演示")]),t._v(" "),t._m(14),t._m(15),t._v(" "),n("p",[t._v("newListener可以用来做事件机制的反射，特殊应用，事件管理等。当任何on事件添加到EventEmitter时，就会触发newListener事件，基于这种模式，我们可以做很多自定义处理.\n \n代码演示")]),t._v(" "),t._m(16),t._m(17),t._v(" "),t._m(18),t._v(" "),n("p",[t._v("代码演示")]),t._v(" "),t._m(19),t._m(20),t._v(" "),t._m(21),t._v(" "),t._m(22),t._v(" "),t._m(23),t._v(" "),t._m(24),t._m(25),t._v(" "),t._m(26),t._v(" "),t._m(27),t._m(28),t._v(" "),n("p",[t._v("用fork嘛，上面讲过了．原理是子程序用process.on, process.send，父程序里用child.on,child.send进行交互.\n代码演示")]),t._v(" "),t._m(29),t._m(30),t._v(" "),t._m(31),t._v(" "),t._m(32),t._v(" "),n("p",[t._v("概念都是一样的，输入，输出，错误，都是流，区别是在父程序眼里，子程序的stdout是输入流，stdin是输出流．")]),t._v(" "),t._m(33),t._v(" "),t._m(34)])},[function(){var t=this.$createElement,s=this._self._c||t;return s("h1",{attrs:{id:"node篇"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#node篇","aria-hidden":"true"}},[this._v("#")]),this._v(" Node篇")])},function(){var t=this.$createElement,s=this._self._c||t;return s("h3",{attrs:{id:"为什么要用node"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#为什么要用node","aria-hidden":"true"}},[this._v("#")]),this._v(" 为什么要用node?")])},function(){var t=this.$createElement,s=this._self._c||t;return s("ul",[s("li",[this._v("简单体现在node使用的是javascript,json来进行编码，人人都会；")]),this._v(" "),s("li",[this._v("强大体现在非阻塞IO,可以适应分块传输数据，较慢的网络环境，尤其擅长高并发访问；")]),this._v(" "),s("li",[this._v("轻量体现在node本身既是代码，又是服务器，前后端使用统一语言;")]),this._v(" "),s("li",[this._v("可扩展体现在可以轻松应对多实例，多服务器架构，同时有海量的第三方应用组件．")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h3",{attrs:{id:"node的构架是什么样子的"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#node的构架是什么样子的","aria-hidden":"true"}},[this._v("#")]),this._v(" node的构架是什么样子的?")])},function(){var t=this.$createElement,s=this._self._c||t;return s("p",[this._v("主要分为三层，应用app >> V8及node内置架构 >> 操作系统."),s("br"),this._v("\nV8是node运行的环境，可以理解为node虚拟机．"),s("br"),this._v("\nnode内置架构又可分为三层: 核心模块(javascript实现) >> c++绑定 >> libuv + CAes + http.")])},function(){var t=this.$createElement,s=this._self._c||t;return s("h3",{attrs:{id:"node有哪些核心模块"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#node有哪些核心模块","aria-hidden":"true"}},[this._v("#")]),this._v(" node有哪些核心模块?")])},function(){var t=this.$createElement,s=this._self._c||t;return s("p",[this._v("EventEmitter, Stream, FS, Net和全局对象"),s("br"),this._v("\nnode全局对象")])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("ol",[n("li",[t._v("node有哪些全局对象?"),n("br"),t._v("\nprocess, console, Buffer和exports")]),t._v(" "),n("li",[t._v("process有哪些常用方法?"),n("br"),t._v("\nprocess.stdin, process.stdout, process.stderr, process.on, process.env, process.argv, process.arch, process.platform, process.exit")]),t._v(" "),n("li",[t._v("console有哪些常用方法?"),n("br"),t._v("\nconsole.log/console.info, console.error/console.warning, console.time/console.timeEnd, console.trace, console.table")]),t._v(" "),n("li",[t._v("node有哪些定时功能?"),n("br"),t._v("\nsetTimeout/clearTimeout, setInterval/clearInterval, setImmediate/clearImmediate, process.nextTick")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h3",{attrs:{id:"node中的事件循环是什么样子的"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#node中的事件循环是什么样子的","aria-hidden":"true"}},[this._v("#")]),this._v(" node中的事件循环是什么样子的?")])},function(){var t=this.$createElement,s=this._self._c||t;return s("h3",{attrs:{id:"node中的buffer如何应用"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#node中的buffer如何应用","aria-hidden":"true"}},[this._v("#")]),this._v(" node中的Buffer如何应用?")])},function(){var t=this.$createElement,s=this._self._c||t;return s("h3",{attrs:{id:"eventemitter"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#eventemitter","aria-hidden":"true"}},[this._v("#")]),this._v(" EventEmitter")])},function(){var t=this.$createElement,s=this._self._c||t;return s("ol",[s("li",[this._v("什么是EventEmitter?"),s("br"),this._v("\nEventEmitter是node中一个实现观察者模式的类，主要功能是监听和发射消息，用于处理多模块交互问题.")]),this._v(" "),s("li",[this._v("如何实现一个EventEmitter?"),s("br"),this._v("\n主要分三步：定义一个子类，调用构造函数，继承EventEmitter\n代码演示")])])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("div",{staticClass:"language-js extra-class"},[n("pre",{pre:!0,attrs:{class:"language-js"}},[n("code",[n("span",{attrs:{class:"token keyword"}},[t._v("var")]),t._v(" util "),n("span",{attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{attrs:{class:"token function"}},[t._v("require")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token string"}},[t._v("'util'")]),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" \n"),n("span",{attrs:{class:"token keyword"}},[t._v("var")]),t._v(" EventEmitter "),n("span",{attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{attrs:{class:"token function"}},[t._v("require")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token string"}},[t._v("'events'")]),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(".")]),t._v("EventEmitter"),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" \n \n"),n("span",{attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),n("span",{attrs:{class:"token function"}},[t._v("MyEmitter")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" \n    EventEmitter"),n("span",{attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{attrs:{class:"token function"}},[t._v("call")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token keyword"}},[t._v("this")]),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" \n"),n("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v(" "),n("span",{attrs:{class:"token comment"}},[t._v("// 构造函数 ")]),t._v("\n \nutil"),n("span",{attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{attrs:{class:"token function"}},[t._v("inherits")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),t._v("MyEmitter"),n("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" EventEmitter"),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),n("span",{attrs:{class:"token comment"}},[t._v("// 继承 ")]),t._v("\n \n"),n("span",{attrs:{class:"token keyword"}},[t._v("var")]),t._v(" em "),n("span",{attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),n("span",{attrs:{class:"token class-name"}},[t._v("MyEmitter")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" \nem"),n("span",{attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{attrs:{class:"token function"}},[t._v("on")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token string"}},[t._v("'hello'")]),n("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{attrs:{class:"token keyword"}},[t._v("function")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),t._v("data"),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" \n    console"),n("span",{attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{attrs:{class:"token function"}},[t._v("log")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token string"}},[t._v("'收到事件hello的数据:'")]),n("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" data"),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" \n"),n("span",{attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),n("span",{attrs:{class:"token comment"}},[t._v("// 接收事件，并打印到控制台 ")]),t._v("\nem"),n("span",{attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{attrs:{class:"token function"}},[t._v("emit")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token string"}},[t._v("'hello'")]),n("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{attrs:{class:"token string"}},[t._v("'EventEmitter传递消息真方便!'")]),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" \n")])])])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("ol",{attrs:{start:"3"}},[n("li",[t._v("EventEmitter有哪些典型应用?\n"),n("ul",[n("li",[t._v("模块间传递消息")]),t._v(" "),n("li",[t._v("回调函数内外传递消息")]),t._v(" "),n("li",[t._v("处理流数据，因为流是在EventEmitter基础上实现的")]),t._v(" "),n("li",[t._v("观察者模式发射触发机制相关应用")])])]),t._v(" "),n("li",[t._v("怎么捕获EventEmitter的错误事件?"),n("br"),t._v("\n监听error事件即可，如果有多个EventEmitter,也可以用domain来统一处理错误事件")])])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("div",{staticClass:"language-js extra-class"},[n("pre",{pre:!0,attrs:{class:"language-js"}},[n("code",[n("span",{attrs:{class:"token keyword"}},[t._v("var")]),t._v(" domain "),n("span",{attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{attrs:{class:"token function"}},[t._v("require")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token string"}},[t._v("'domain'")]),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" \n"),n("span",{attrs:{class:"token keyword"}},[t._v("var")]),t._v(" myDomain "),n("span",{attrs:{class:"token operator"}},[t._v("=")]),t._v(" domain"),n("span",{attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{attrs:{class:"token function"}},[t._v("create")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" \nmyDomain"),n("span",{attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{attrs:{class:"token function"}},[t._v("on")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token string"}},[t._v("'error'")]),n("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{attrs:{class:"token keyword"}},[t._v("function")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),t._v("err"),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" \n    console"),n("span",{attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{attrs:{class:"token function"}},[t._v("log")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token string"}},[t._v("'domain接收到的错误事件:'")]),n("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" err"),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" \n"),n("span",{attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),n("span",{attrs:{class:"token comment"}},[t._v("// 接收事件并打印 ")]),t._v("\nmyDomain"),n("span",{attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{attrs:{class:"token function"}},[t._v("run")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token keyword"}},[t._v("function")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" \n    "),n("span",{attrs:{class:"token keyword"}},[t._v("var")]),t._v(" emitter1 "),n("span",{attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),n("span",{attrs:{class:"token class-name"}},[t._v("MyEmitter")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" \n    emitter1"),n("span",{attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{attrs:{class:"token function"}},[t._v("emit")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token string"}},[t._v("'error'")]),n("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{attrs:{class:"token string"}},[t._v("'错误事件来自emitter1'")]),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" \n    emitter2 "),n("span",{attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),n("span",{attrs:{class:"token class-name"}},[t._v("MyEmitter")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" \n    emitter2"),n("span",{attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{attrs:{class:"token function"}},[t._v("emit")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token string"}},[t._v("'error'")]),n("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{attrs:{class:"token string"}},[t._v("'错误事件来自emitter2'")]),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" \n"),n("span",{attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" \n")])])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h3",{attrs:{id:"eventemitter中的newlistenser事件有什么用处"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#eventemitter中的newlistenser事件有什么用处","aria-hidden":"true"}},[this._v("#")]),this._v(" EventEmitter中的newListenser事件有什么用处?")])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("div",{staticClass:"language-js extra-class"},[n("pre",{pre:!0,attrs:{class:"language-js"}},[n("code",[n("span",{attrs:{class:"token keyword"}},[t._v("var")]),t._v(" emitter3 "),n("span",{attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),n("span",{attrs:{class:"token class-name"}},[t._v("MyEmitter")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nemitter3"),n("span",{attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{attrs:{class:"token function"}},[t._v("on")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token string"}},[t._v("'newListener'")]),n("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{attrs:{class:"token keyword"}},[t._v("function")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),t._v("name"),n("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" listener"),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n    console"),n("span",{attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{attrs:{class:"token function"}},[t._v("log")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token string"}},[t._v('"新事件的名字:"')]),n("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" name"),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" \n    console"),n("span",{attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{attrs:{class:"token function"}},[t._v("log")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token string"}},[t._v('"新事件的代码:"')]),n("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" listener"),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" \n    "),n("span",{attrs:{class:"token function"}},[t._v("setTimeout")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token keyword"}},[t._v("function")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" console"),n("span",{attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{attrs:{class:"token function"}},[t._v("log")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token string"}},[t._v('"我是自定义延时处理机制"')]),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),n("span",{attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{attrs:{class:"token number"}},[t._v("1000")]),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" \n"),n("span",{attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nemitter3"),n("span",{attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{attrs:{class:"token function"}},[t._v("on")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token string"}},[t._v("'hello'")]),n("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{attrs:{class:"token keyword"}},[t._v("function")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n    console"),n("span",{attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{attrs:{class:"token function"}},[t._v("log")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token string"}},[t._v("'hello　node'")]),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" \n"),n("span",{attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h3",{attrs:{id:"stream"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#stream","aria-hidden":"true"}},[this._v("#")]),this._v(" Stream")])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("ol",[n("li",[t._v("什么是Stream?"),n("br"),t._v("\nstream是基于事件EventEmitter的数据管理模式．由各种不同的抽象接口组成，主要包括可写，可读，可读写，可转换等几种类型．")]),t._v(" "),n("li",[t._v("Stream有什么好处?"),n("br"),t._v("\n非阻塞式数据处理提升效率，片断处理节省内存，管道处理方便可扩展等.")]),t._v(" "),n("li",[t._v("Stream有哪些典型应用?"),n("br"),t._v("\n文件，网络，数据转换，音频视频等.")]),t._v(" "),n("li",[t._v("怎么捕获Stream的错误事件?"),n("br"),t._v("\n监听error事件，方法同EventEmitter.")]),t._v(" "),n("li",[t._v("有哪些常用Stream,分别什么时候使用?"),n("br"),t._v("\nReadable为可被读流，在作为输入数据源时使用；Writable为可被写流,在作为输出源时使用；Duplex为可读写流,它作为输出源接受被写入，同时又作为输入源被后面的流读出．Transform机制和Duplex一样，都是双向流，区别时Transfrom只需要实现一个函数_transfrom(chunk, encoding, callback);而Duplex需要分别实现_read(size)函数和_write(chunk, encoding, callback)函数.")]),t._v(" "),n("li",[t._v("实现一个Writable Stream?"),n("br"),t._v("\n三步走:"),n("br"),t._v("\n1)构造函数call Writable"),n("br"),t._v("\n2)继承Writable"),n("br"),t._v("\n3)实现_write(chunk, encoding, callback)函数")])])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("div",{staticClass:"language-js extra-class"},[n("pre",{pre:!0,attrs:{class:"language-js"}},[n("code",[n("span",{attrs:{class:"token keyword"}},[t._v("var")]),t._v(" Writable "),n("span",{attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{attrs:{class:"token function"}},[t._v("require")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token string"}},[t._v("'stream'")]),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Writable"),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),n("span",{attrs:{class:"token keyword"}},[t._v("var")]),t._v(" util "),n("span",{attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{attrs:{class:"token function"}},[t._v("require")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token string"}},[t._v("'util'")]),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n \n"),n("span",{attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),n("span",{attrs:{class:"token function"}},[t._v("MyWritable")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),t._v("options"),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n    Writable"),n("span",{attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{attrs:{class:"token function"}},[t._v("call")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token keyword"}},[t._v("this")]),n("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" options"),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" \n"),n("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v(" "),n("span",{attrs:{class:"token comment"}},[t._v("// 构造函数 ")]),t._v("\nutil"),n("span",{attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{attrs:{class:"token function"}},[t._v("inherits")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),t._v("MyWritable"),n("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" Writable"),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),n("span",{attrs:{class:"token comment"}},[t._v("// 继承自Writable ")]),t._v("\nMyWritable"),n("span",{attrs:{class:"token punctuation"}},[t._v(".")]),t._v("prototype"),n("span",{attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{attrs:{class:"token function-variable function"}},[t._v("_write")]),t._v(" "),n("span",{attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{attrs:{class:"token keyword"}},[t._v("function")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),t._v("chunk"),n("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" encoding"),n("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" callback"),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n    console"),n("span",{attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{attrs:{class:"token function"}},[t._v("log")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token string"}},[t._v('"被写入的数据是:"')]),n("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" chunk"),n("span",{attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{attrs:{class:"token function"}},[t._v("toString")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),n("span",{attrs:{class:"token comment"}},[t._v("// 此处可对写入的数据进行处理 ")]),t._v("\n    "),n("span",{attrs:{class:"token function"}},[t._v("callback")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" \n"),n("span",{attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n \nprocess"),n("span",{attrs:{class:"token punctuation"}},[t._v(".")]),t._v("stdin"),n("span",{attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{attrs:{class:"token function"}},[t._v("pipe")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),n("span",{attrs:{class:"token class-name"}},[t._v("MyWritable")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),n("span",{attrs:{class:"token comment"}},[t._v("// stdin作为输入源，MyWritable作为输出源  ")]),t._v("\n")])])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h3",{attrs:{id:"文件系统"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#文件系统","aria-hidden":"true"}},[this._v("#")]),this._v(" 文件系统")])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("ol",[n("li",[t._v("内置的fs模块架构是什么样子的?"),n("br"),t._v("\nfs模块主要由下面几部分组成:\n"),n("ol",[n("li",[t._v("POSIX文件Wrapper,对应于操作系统的原生文件操作")]),t._v(" "),n("li",[t._v("文件流 fs.createReadStream和fs.createWriteStream")]),t._v(" "),n("li",[t._v("同步文件读写,fs.readFileSync和fs.writeFileSync")]),t._v(" "),n("li",[t._v("异步文件读写, fs.readFile和fs.writeFile")])])]),t._v(" "),n("li",[t._v("读写一个文件有多少种方法?"),n("br"),t._v("\n总体来说有四种:\n"),n("ol",[n("li",[t._v("POSIX式低层读写")]),t._v(" "),n("li",[t._v("流式读写")]),t._v(" "),n("li",[t._v("同步文件读写")]),t._v(" "),n("li",[t._v("异步文件读写")])])]),t._v(" "),n("li",[t._v("怎么读取json配置文件?"),n("br"),t._v("\n主要有两种方式"),n("br"),t._v("\n第一种是利用node内置的require('data.json')机制，直接得到js对象;"),n("br"),t._v("\n第二种是读入文件入内容，然后用JSON.parse(content)转换成js对象．"),n("br"),t._v("\n二者的区别是require机制情况下，如果多个模块都加载了同一个json文件，那么其中一个改变了js对象，其它跟着改变，这是由node模块的缓存机制造成的，只有一个js模块对象; 第二种方式则可以随意改变加载后的js变量，而且各模块互不影响，因为他们都是独立的，是多个js对象.")]),t._v(" "),n("li",[t._v("fs.watch和fs.watchFile有什么区别，怎么应用?"),n("br"),t._v("\n二者主要用来监听文件变动．fs.watch利用操作系统原生机制来监听，可能不适用网络文件系统; fs.watchFile则是定期检查文件状态变更，适用于网络文件系统，但是相比fs.watch有些慢，因为不是实时机制．")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h3",{attrs:{id:"网络"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#网络","aria-hidden":"true"}},[this._v("#")]),this._v(" 网络")])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("ol",[n("li",[t._v("node的网络模块架构是什么样子的?"),n("br"),t._v("\nnode全面支持各种网络服务器和客户端，包括tcp, http/https, tcp, udp, dns, tls/ssl等.")]),t._v(" "),n("li",[t._v("node是怎样支持https,tls的?"),n("br"),t._v("\n主要实现以下几个步骤即可: 1) openssl生成公钥私钥 2) 服务器或客户端使用https替代http 3) 服务器或客户端加载公钥私钥证书")]),t._v(" "),n("li",[t._v("实现一个简单的http服务器?(必须会手写)"),n("br"),t._v("\n经典又很没毛意义的一个题目．思路是加载http模块，创建服务器，监听端口.\n \n代码演示")])])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("div",{staticClass:"language-js extra-class"},[n("pre",{pre:!0,attrs:{class:"language-js"}},[n("code",[n("span",{attrs:{class:"token keyword"}},[t._v("var")]),t._v(" http "),n("span",{attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{attrs:{class:"token function"}},[t._v("require")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token string"}},[t._v("'http'")]),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),n("span",{attrs:{class:"token comment"}},[t._v("// 加载http模块 ")]),t._v("\n \nhttp"),n("span",{attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{attrs:{class:"token function"}},[t._v("createServer")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token keyword"}},[t._v("function")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),t._v("req"),n("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" res"),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" \n    res"),n("span",{attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{attrs:{class:"token function"}},[t._v("writeHead")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token number"}},[t._v("200")]),n("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{attrs:{class:"token string"}},[t._v("'Content-Type'")]),n("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),n("span",{attrs:{class:"token string"}},[t._v("'text/html'")]),n("span",{attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),n("span",{attrs:{class:"token comment"}},[t._v("// 200代表状态成功, 文档类型是给浏览器识别用的 ")]),t._v("\n    res"),n("span",{attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{attrs:{class:"token function"}},[t._v("write")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token string"}},[t._v('\'<meta charset="UTF-8"><h1>我是标题啊！</h1><font color="red">这么原生，初级的服务器，下辈子能用着吗?!</font>\'')]),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),n("span",{attrs:{class:"token comment"}},[t._v("// 返回给客户端的html数据 ")]),t._v("\n    res"),n("span",{attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{attrs:{class:"token function"}},[t._v("end")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),n("span",{attrs:{class:"token comment"}},[t._v("// 结束输出流 ")]),t._v("\n"),n("span",{attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{attrs:{class:"token function"}},[t._v("listen")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token number"}},[t._v("3000")]),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),n("span",{attrs:{class:"token comment"}},[t._v("// 绑定3ooo, 查看效果请访问 http://localhost:3000 ")]),t._v("\n")])])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h3",{attrs:{id:"child-process"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#child-process","aria-hidden":"true"}},[this._v("#")]),this._v(" child-process")])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("ol",[n("li",[t._v("为什么需要child-process?"),n("br"),t._v("\nnode是异步非阻塞的，这对高并发非常有效．可是我们还有其它一些常用需求，比如和操作系统shell命令交互，调用可执行文件，创建子进程进行阻塞式访问或高CPU计算等，child-process就是为满足这些需求而生的．child-process顾名思义，就是把node阻塞的工作交给子进程去做．")]),t._v(" "),n("li",[t._v("exec,execFile,spawn和fork都是做什么用的?"),n("br"),t._v("\nexec可以用操作系统原生的方式执行各种命令，如管道 cat ab.txt | grep hello; execFile是执行一个文件; spawn是流式和操作系统进行交互; fork是两个node程序(javascript)之间时行交互.")]),t._v(" "),n("li",[t._v("实现一个简单的命令行交互程序?"),n("br"),t._v("\n那就用spawn吧"),n("br"),t._v("\n \n代码演示")])])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("div",{staticClass:"language-js extra-class"},[n("pre",{pre:!0,attrs:{class:"language-js"}},[n("code",[n("span",{attrs:{class:"token keyword"}},[t._v("var")]),t._v(" cp "),n("span",{attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{attrs:{class:"token function"}},[t._v("require")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token string"}},[t._v("'child_process'")]),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" \n"),n("span",{attrs:{class:"token keyword"}},[t._v("var")]),t._v(" child "),n("span",{attrs:{class:"token operator"}},[t._v("=")]),t._v(" cp"),n("span",{attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{attrs:{class:"token function"}},[t._v("spawn")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token string"}},[t._v("'echo'")]),n("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{attrs:{class:"token punctuation"}},[t._v("[")]),n("span",{attrs:{class:"token string"}},[t._v("'你好'")]),n("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{attrs:{class:"token string"}},[t._v('"钩子"')]),n("span",{attrs:{class:"token punctuation"}},[t._v("]")]),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),n("span",{attrs:{class:"token comment"}},[t._v("// 执行命令 ")]),t._v("\n\nchild"),n("span",{attrs:{class:"token punctuation"}},[t._v(".")]),t._v("stdout"),n("span",{attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{attrs:{class:"token function"}},[t._v("pipe")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),t._v("process"),n("span",{attrs:{class:"token punctuation"}},[t._v(".")]),t._v("stdout"),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),n("span",{attrs:{class:"token comment"}},[t._v("// child.stdout是输入流，process.stdout是输出流 ")]),t._v("\n"),n("span",{attrs:{class:"token comment"}},[t._v("// 这句的意思是将子进程的输出作为当前程序的输入流，然后重定向到当前程序的标准输出，即控制台")]),t._v("\n")])])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h3",{attrs:{id:"两个node程序之间怎样交互"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#两个node程序之间怎样交互","aria-hidden":"true"}},[this._v("#")]),this._v(" 两个node程序之间怎样交互?")])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("div",{staticClass:"language-js extra-class"},[n("pre",{pre:!0,attrs:{class:"language-js"}},[n("code",[n("span",{attrs:{class:"token number"}},[t._v("1")]),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" fork"),n("span",{attrs:{class:"token operator"}},[t._v("-")]),t._v("parent"),n("span",{attrs:{class:"token punctuation"}},[t._v(".")]),t._v("js \n"),n("span",{attrs:{class:"token keyword"}},[t._v("var")]),t._v(" cp "),n("span",{attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{attrs:{class:"token function"}},[t._v("require")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token string"}},[t._v("'child_process'")]),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" \n"),n("span",{attrs:{class:"token keyword"}},[t._v("var")]),t._v(" child "),n("span",{attrs:{class:"token operator"}},[t._v("=")]),t._v(" cp"),n("span",{attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{attrs:{class:"token function"}},[t._v("fork")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token string"}},[t._v("'./fork-child.js'")]),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" \nchild"),n("span",{attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{attrs:{class:"token function"}},[t._v("on")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token string"}},[t._v("'message'")]),n("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{attrs:{class:"token keyword"}},[t._v("function")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),t._v("msg"),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" \n    console"),n("span",{attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{attrs:{class:"token function"}},[t._v("log")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token string"}},[t._v("'老爸从儿子接受到数据:'")]),n("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" msg"),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" \n"),n("span",{attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" \nchild"),n("span",{attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{attrs:{class:"token function"}},[t._v("send")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token string"}},[t._v("'我是你爸爸，送关怀来了!'")]),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" \n \n"),n("span",{attrs:{class:"token number"}},[t._v("2")]),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" fork"),n("span",{attrs:{class:"token operator"}},[t._v("-")]),t._v("child"),n("span",{attrs:{class:"token punctuation"}},[t._v(".")]),t._v("js \nprocess"),n("span",{attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{attrs:{class:"token function"}},[t._v("on")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token string"}},[t._v("'message'")]),n("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{attrs:{class:"token keyword"}},[t._v("function")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),t._v("msg"),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" \n    console"),n("span",{attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{attrs:{class:"token function"}},[t._v("log")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token string"}},[t._v('"儿子从老爸接收到的数据:"')]),n("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" msg"),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" \n    process"),n("span",{attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{attrs:{class:"token function"}},[t._v("send")]),n("span",{attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{attrs:{class:"token string"}},[t._v('"我不要关怀，我要银民币！"')]),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" \n"),n("span",{attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" \n")])])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h3",{attrs:{id:"怎样让一个js文件变得像linux命令一样可执行"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#怎样让一个js文件变得像linux命令一样可执行","aria-hidden":"true"}},[this._v("#")]),this._v(" 怎样让一个js文件变得像linux命令一样可执行?")])},function(){var t=this.$createElement,s=this._self._c||t;return s("ol",[s("li",[this._v("在myCommand.js文件头部加入#!/usr/bin/env node")]),this._v(" "),s("li",[this._v("chmod命令把js文件改为可执行即可")]),this._v(" "),s("li",[this._v("进入文件目录，命令行输入myComand就是相当于node myComand.js了")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h3",{attrs:{id:"child-process和process的stdin-stdout-stderror是一样的吗"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#child-process和process的stdin-stdout-stderror是一样的吗","aria-hidden":"true"}},[this._v("#")]),this._v(" child-process和process的stdin,stdout,stderror是一样的吗?")])},function(){var t=this.$createElement,s=this._self._c||t;return s("h3",{attrs:{id:"node高级话题-异步，部署，性能调优，异常调试等"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#node高级话题-异步，部署，性能调优，异常调试等","aria-hidden":"true"}},[this._v("#")]),this._v(" node高级话题(异步，部署，性能调优，异常调试等)")])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("ol",[n("li",[n("p",[t._v("node中的异步和同步怎么理解"),n("br"),t._v("\nnode是单线程的，异步是通过一次次的循环事件队列来实现的．同步则是说阻塞式的IO,这在高并发环境会是一个很大的性能问题，所以同步一般只在基础框架的启动时使用，用来加载配置文件，初始化程序什么的．")])]),t._v(" "),n("li",[n("p",[t._v("有哪些方法可以进行异步流程的控制?")]),t._v(" "),n("ul",[n("li",[t._v("多层嵌套回调")]),t._v(" "),n("li",[t._v("为每一个回调写单独的函数，函数里边再回调")]),t._v(" "),n("li",[t._v("用第三方框架比方async, q, promise等")])])]),t._v(" "),n("li",[n("p",[t._v("怎样绑定node程序到80端口?")]),t._v(" "),n("ol",[n("li",[t._v("sudo")]),t._v(" "),n("li",[t._v("apache/nginx代理")]),t._v(" "),n("li",[t._v("用操作系统的firewall iptables进行端口重定向")])])]),t._v(" "),n("li",[n("p",[t._v("有哪些方法可以让node程序遇到错误后自动重启(守护进程)?"),n("br"),t._v("\nforever、 nohup、pm2")])]),t._v(" "),n("li",[n("p",[t._v("怎样充分利用多个CPU?"),n("br"),t._v("\n一个CPU运行一个node实例")])]),t._v(" "),n("li",[n("p",[t._v("怎样调试node程序?"),n("br"),t._v("\nnode --debug app.js 和node-inspector")])]),t._v(" "),n("li",[n("p",[t._v("express response有哪些常用方法")]),t._v(" "),n("ul",[n("li",[t._v("res.download() 弹出文件下载")]),t._v(" "),n("li",[t._v("res.end() 结束response")]),t._v(" "),n("li",[t._v("res.json() 返回json")]),t._v(" "),n("li",[t._v("res.jsonp() 返回jsonp")]),t._v(" "),n("li",[t._v("res.redirect() 重定向请求")]),t._v(" "),n("li",[t._v("res.render() 渲染模板")]),t._v(" "),n("li",[t._v("res.send() 返回多种形式数据")]),t._v(" "),n("li",[t._v("res.sendFile 返回文件")]),t._v(" "),n("li",[t._v("res.sendStatus() 返回状态")])])]),t._v(" "),n("li",[n("p",[t._v("apache,nginx有什么区别?"),n("br"),t._v("\n二者都是代理服务器，功能类似。apache应用简单，相当广泛，nginx在分布式，静态转发方面比较有优势。")])])])}],!1,null,null,null);s.default=e.exports}}]);