-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode.txt
127 lines (48 loc) · 1.87 KB
/
node.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<一>
电脑上已有老版本node要安装最新版本node时, 可直接在官网下载最新版本安装,注意:在安装完成后,一般要安装cnpm,
npm install -g cnpm --registry=https://registry.npm.taobao.org ,
或者在启动命令的路径下添加.npmrc文件(将源指向淘宝npm镜像),内容为:
phantomjs_cdnurl=http://cnpmjs.org/downloads
sass_binary_site=https://npm.taobao.org/mirrors/node-sass
registry=https://registry.npm.taobao.org
<二>
exports 与 module.exports 的区别:
exports 是 module.exports 对象的引用, 相当于 const exports = module.exports,
正因为exports 是 module.exports 对象的引用,所以在使用exports时不能改变其原有指针,例如:
exports = {
text: 'xxx'
}
上面的使用方式是错误的,因为引用地址改变了,此时导出此模块时module.exports为{},所以使用exports只能在该引用上添加属性,例如:
exports.test = 'xxx'; 正确
而module.exports则可以以下面的两种方式使用:
module.exports.test = 'xxx'; 或 module.exports = { test: 'xxx' }
<三>
node 全局对象 global:
commonjs : require, module, exports
buffer
process
console
timer(定时器相关): setInterval, setTimeout, setImmediate
<四>
setTimeout, setImmediate 和 process.nextTick 的区别:
process.nextTick:在当前事件循环的队尾这行
setTimeout:在当前事件循环结束 和 在下一个事件循环开始之前执行
setImmediate :在下一个事件循环的队首执行
即process.nextTick早于setTimeout执行,setTimeout又早于setImmediate 执行
<五>
以下npm包可以自动重新启动node服务:
nodemon(推荐,github上的star数多), supervisor
<六>
由于现在的浏览器都支持 gzip, deflate等, 所以要在服务器实现,node提供内置zlib模块以供使用
<七>
curl :调试网络请求的工具
<八>
怎么爬去某一网站上的图片, 音频,视频等
<九>
在安装完node后,要全局 npm i node-sass -g,不然有的npm包安装时会报错
<十>
node进程
http://blog.fens.me/nodejs-child-process/
https://cnodejs.org/topic/518b679763e9f8a5424406e9
(11)设置node运行内存(单位:KB)
set NODE_OPTIONS=--max_old_space_size=4096