-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.xml
1981 lines (1902 loc) · 344 KB
/
search.xml
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="utf-8"?>
<search>
<entry>
<title>使用Nexmo发送中文短信</title>
<url>/2016/07/18/send-chinese-sms-using-nexmo/</url>
<content><![CDATA[<p>最近公司的项目要发送短信通知,因为用户都是国际用户,因此国际短信是必不可少的,一开始打算选择国内的【云片】平台,但是签名不能是全英文有些尴尬,最终选择了【Nexmo】。</p>
<p>Nexmo发送短信的<a href="https://docs.nexmo.com/messaging/sms-api" target="_blank" rel="noopener">API</a>还是非常简单的,一些语言也给出了详细的使用例子。这里copy一下nodejs的例子。</p>
<p>需要注意的是,如果发送的内容带有中文等字符,需要将<code>type</code>设置为<code>unicode</code>,不然的话收到的短信中这些字符会全部为问号。</p>
<a id="more"></a>
<pre><code class="js"><span class="keyword">var</span> https = <span class="built_in">require</span>(<span class="string">'https'</span>);
<span class="keyword">var</span> data = <span class="built_in">JSON</span>.stringify({
api_key: <span class="string">'API_KEY'</span>,
api_secret: <span class="string">'API_SECRET'</span>,
to: <span class="string">'441632960960'</span>,
<span class="keyword">from</span>: <span class="string">'441632960961'</span>,
text: <span class="string">'你好'</span>,
type: <span class="string">'unicode'</span>
});
<span class="keyword">var</span> options = {
host: <span class="string">'rest.nexmo.com'</span>,
path: <span class="string">'/sms/json'</span>,
port: <span class="number">443</span>,
method: <span class="string">'POST'</span>,
headers: {
<span class="string">'Content-Type'</span>: <span class="string">'application/json'</span>,
<span class="string">'Content-Length'</span>: Buffer.byteLength(data)
}
};
<span class="keyword">var</span> req = https.request(options);
req.write(data);
req.end();
<span class="keyword">var</span> responseData = <span class="string">''</span>;
req.on(<span class="string">'response'</span>, <span class="function"><span class="keyword">function</span>(<span class="params">res</span>)</span>{
res.on(<span class="string">'data'</span>, <span class="function"><span class="keyword">function</span>(<span class="params">chunk</span>)</span>{
responseData += chunk;
});
res.on(<span class="string">'end'</span>, <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>{
<span class="built_in">console</span>.log(<span class="built_in">JSON</span>.parse(responseData));
});
});</code></pre>
]]></content>
<categories>
<category>NodeJS</category>
</categories>
<tags>
<tag>nodejs</tag>
</tags>
</entry>
<entry>
<title>【翻译】Nodejs - Breaking changes between v5 and v6</title>
<url>/2016/05/18/nodejs-breaking-changes-between-v5-and-v6/</url>
<content><![CDATA[<p>英语水平比较渣,如果有翻译不对的地方请指出,谢谢。<br>原文地址:<a href="https://github.com/nodejs/wiki-archive/blob/master/Breaking-changes-between-v5-and-v6.md" target="_blank" rel="noopener">Nodejs - Breaking changes between v5 and v6</a></p>
<hr>
<p>查看之前的改动日志,请查看<a href="https://github.com/nodejs/node/wiki/Breaking-changes-between-v4-and-v5" target="_blank" rel="noopener">v4 to v5</a>页面。</p>
<p>89个提交被标记为<code>semver-major</code>。</p>
<a id="more"></a>
<p><strong>注意</strong>:<code>#</code> 与 <code>.prototype.</code> 同意,表示该类的实例的属性是可用的。<br>例如:<code>Object#toString()</code> 等同于 <code>Object.prototype.toString()</code>。</p>
<h2 id="By-Subsystem"><a href="#By-Subsystem" class="headerlink" title="By Subsystem"></a>By Subsystem</h2><h3 id="buffer"><a href="#buffer" class="headerlink" title="buffer"></a>buffer</h3><p>[<a href="https://nodejs.org/dist/latest-v6.x/docs/api/buffer.html" target="_blank" rel="noopener">Docs</a>]</p>
<ul>
<li>弃用<code>new Buffer()</code>并由一些列新增的<a href="https://nodejs.org/dist/latest-v6.x/docs/api/buffer.html#buffer_buffer_from_buffer_alloc_and_buffer_allocunsafe" target="_blank" rel="noopener">Buffer API: <code>Buffer.from()</code>,<code>Buffer.alloc()</code>,<code>Buffer.allocUnsafe()</code></a>替代。<ul>
<li>Refs: <a href="https://github.com/nodejs/node/commit/85ab4a5f12" target="_blank" rel="noopener"><code>85ab4a5f12</code></a>,<a href="https://github.com/nodejs/node/pull/4682" target="_blank" rel="noopener">#4682</a></li>
</ul>
</li>
<li>移除之前弃用的<code>Buffer#write(string, encoding, offset, length)</code><ul>
<li><a href="https://nodejs.org/dist/latest-v6.x/docs/api/buffer.html#buffer_buf_write_string_offset_length_encoding" target="_blank" rel="noopener"><code>Buffer#write()</code></a>保留其他调用方式,如<code>Buffer#write(string[, encoding])</code>。</li>
<li>Refs: <a href="https://github.com/nodejs/node/commit/2c55cc2d2c" target="_blank" rel="noopener"><code>2c55cc2d2c</code></a>, <a href="https://github.com/nodejs/node/pull/5048" target="_blank" rel="noopener">#5048</a></li>
</ul>
</li>
<li>移除之前弃用的<code>Buffer#{get|set}</code>方法。<ul>
<li><code>Buffer#get(index)</code>由<code>buffer[index]</code>替代。</li>
<li><code>Buffer#set(index, value)</code>由<code>buffer[index] = value</code>替代。</li>
<li>Refs: <a href="https://github.com/nodejs/node/commit/101bca988c" target="_blank" rel="noopener"><code>101bca988c</code></a>, <a href="https://github.com/nodejs/node/pull/4594" target="_blank" rel="noopener">#4594</a></li>
</ul>
</li>
<li><code>new Buffer(length, encoding)</code>现在会抛出异常。<ul>
<li>如果传入的<code>length</code>参数是数字的话没有什么影响(译者注:个人认为这里应该是传入参数是string类型没有影响,推荐详细阅读PR),这个改动用来指出一种潜在的安全问题。</li>
<li>Refs: <a href="https://github.com/nodejs/node/commit/3b27dd5ce1" target="_blank" rel="noopener"><code>3b27dd5ce1</code></a>, <a href="https://github.com/nodejs/node/pull/4514" target="_blank" rel="noopener">#4514</a></li>
</ul>
</li>
<li><a href="https://nodejs.org/dist/latest-v6.x/docs/api/buffer.html#buffer_class_slowbuffer" target="_blank" rel="noopener"><code>SlowBuffer</code></a>由<code>Buffer.allocUnsafeSlow()</code>替代并在文档中给出弃用警告。<ul>
<li>Refs: <a href="https://github.com/nodejs/node/commit/3fe204c700" target="_blank" rel="noopener"><code>3fe204c700</code></a>, <a href="https://github.com/nodejs/node/commit/627524973a" target="_blank" rel="noopener"><code>627524973a</code></a>, <a href="https://github.com/nodejs/node/pull/5833" target="_blank" rel="noopener">#5833</a></li>
</ul>
</li>
</ul>
<h3 id="cluster"><a href="#cluster" class="headerlink" title="cluster"></a>cluster</h3><p>[<a href="https://nodejs.org/dist/latest-v6.x/docs/api/cluster.html" target="_blank" rel="noopener">Docs</a>]</p>
<ul>
<li>弃用<code>Worker#suicide</code>属性并由语义更清晰的<a href="https://nodejs.org/dist/latest-v6.x/docs/api/cluster.html#cluster_worker_exitedafterdisconnect" target="_blank" rel="noopener"><code>Worker#exitedAfterDisconnect</code></a>替代。<ul>
<li>功能保持不变。</li>
<li>Refs: <a href="https://github.com/nodejs/node/commit/4f619bde4c" target="_blank" rel="noopener"><code>4f619bde4c</code></a>, <a href="https://github.com/nodejs/node/pull/3743" target="_blank" rel="noopener">#3743</a></li>
</ul>
</li>
<li>cluster的<a href="https://nodejs.org/dist/latest-v6.x/docs/api/cluster.html#cluster_event_message_1" target="_blank" rel="noopener"><code>'message'</code></a>事件的回调函数现在有三个参数,第一个参数为<code>worker</code>。<ul>
<li>之前的回调函数的参数为<code>(message, handle)</code>,现在是<code>(worker, message, handle)</code>。</li>
<li>Refs: <a href="https://github.com/nodejs/node/commit/66f4586dd0" target="_blank" rel="noopener"><code>66f4586dd0</code></a>, <a href="https://github.com/nodejs/node/pull/5361" target="_blank" rel="noopener">#5361</a></li>
</ul>
</li>
</ul>
<h3 id="console"><a href="#console" class="headerlink" title="console"></a>console</h3><p>[<a href="https://nodejs.org/dist/latest-v6.x/docs/api/console.html" target="_blank" rel="noopener">Docs</a>]</p>
<ul>
<li><a href="https://nodejs.org/dist/latest-v6.x/docs/api/console.html#console_console_timeend_label" target="_blank" rel="noopener"><code>Console#timeEnd(label)</code></a>现在将在完成后清除label。<ul>
<li>之前会将label遗留在<code>_times</code>中.</li>
<li>Refs: <a href="https://github.com/nodejs/node/commit/a5cce79ec3" target="_blank" rel="noopener"><code>a5cce79ec3</code></a>, <a href="https://github.com/nodejs/node/pull/3562" target="_blank" rel="noopener">#3562</a></li>
</ul>
</li>
<li>如果label不存在,<code>Console#timeEnd(label)</code>现在只会发出警告。<ul>
<li>之前会抛出错误。</li>
<li>Refs: <a href="https://github.com/nodejs/node/commit/1c84579031" target="_blank" rel="noopener"><code>1c84579031</code></a>, <a href="https://github.com/nodejs/node/pull/5901" target="_blank" rel="noopener">#5901</a></li>
</ul>
</li>
</ul>
<h3 id="crypto"><a href="#crypto" class="headerlink" title="crypto"></a>crypto</h3><p>[<a href="https://nodejs.org/dist/latest-v6.x/docs/api/crypto.html" target="_blank" rel="noopener">Docs</a>]</p>
<ul>
<li>改进C++代码中的错误信息的格式。<ul>
<li>Refs: <a href="https://github.com/nodejs/node/commit/41feaa89e0" target="_blank" rel="noopener"><code>41feaa89e0</code></a>, <a href="https://github.com/nodejs/node/pull/3100" target="_blank" rel="noopener">#3100</a>, <a href="https://github.com/nodejs/node/commit/1d9451bb5a" target="_blank" rel="noopener"><code>1d9451bb5a</code></a>, <a href="https://github.com/nodejs/node/pull/6042" target="_blank" rel="noopener">#6042</a></li>
</ul>
</li>
<li>如果node构建时没有crypto支持,<code>require('crypto')</code>会抛出异常。<ul>
<li><code>require('tls')</code>和<code>require('https')</code>同上。</li>
<li>Refs: <a href="https://github.com/nodejs/node/commit/f429fe1b88" target="_blank" rel="noopener"><code>f429fe1b88</code></a>, <a href="https://github.com/nodejs/node/pull/5611" target="_blank" rel="noopener">#5611</a></li>
</ul>
</li>
<li><a href="https://nodejs.org/dist/latest-v6.x/docs/api/crypto.html#crypto_class_certificate" target="_blank" rel="noopener"><code>crypto.Certificate</code></a>不再有<code>_handle</code> 属性。<ul>
<li>之前需要<code>_handle</code>属性的类方法现在直接调用c++ binding。</li>
<li>Refs: <a href="https://github.com/nodejs/node/commit/a37401e061" target="_blank" rel="noopener"><code>a37401e061</code></a>, <a href="https://github.com/nodejs/node/pull/5382" target="_blank" rel="noopener">#5382</a></li>
</ul>
</li>
<li><a href="https://nodejs.org/dist/latest-v6.x/docs/api/crypto.html#crypto_crypto_pbkdf2_password_salt_iterations_keylen_digest_callback" target="_blank" rel="noopener"><code>crypto.pbkdf2()</code></a>的<code>digest</code>参数现在是必传的。<ul>
<li>目前不使用digest参数会打印弃用的警告。</li>
</ul>
</li>
<li>crypto所有方法的默认编码为<code>utf8</code>。<ul>
<li>之前默认的编码是<code>binary</code> (<code>latin1</code>的nodejs版)。</li>
<li>Refs: <a href="https://github.com/nodejs/node/commit/b010c87164" target="_blank" rel="noopener"><code>b010c87164</code></a>, <a href="https://github.com/nodejs/node/pull/5522" target="_blank" rel="noopener">#5522</a></li>
</ul>
</li>
<li>默认关闭FIPS兼容模式即使node是在FIPS规则下构建。<ul>
<li>注意:正常发布的node不是在启用FIPS情况下构建的。</li>
<li>Refs: <a href="https://github.com/nodejs/node/commit/7c48cb5601" target="_blank" rel="noopener"><code>7c48cb5601</code></a>, <a href="https://github.com/nodejs/node/pull/5181" target="_blank" rel="noopener">#5181</a></li>
</ul>
</li>
</ul>
<h3 id="dgram"><a href="#dgram" class="headerlink" title="dgram"></a>dgram</h3><p>[<a href="https://nodejs.org/dist/latest-v6.x/docs/api/dgram.html" target="_blank" rel="noopener">Docs</a>]</p>
<ul>
<li>如果执行<a href="https://nodejs.org/dist/latest-v6.x/docs/api/dgram.html#dgram_socket_send_msg_offset_length_port_address_callback" target="_blank" rel="noopener"><code>Socket#send()</code></a>没有发生错误,回调函数的<code>error</code>参数现在为<code>null</code>,而不是<code>0</code>.<ul>
<li>在io.js 1.0.0中<a href="https://github.com/nodejs/node/commit/c9fd9e2162" target="_blank" rel="noopener"><code>c9fd9e2</code></a>之前就是这样的。</li>
<li>Refs: <a href="https://github.com/nodejs/node/commit/4bc1cccb22" target="_blank" rel="noopener"><code>4bc1cccb22</code></a>, <a href="https://github.com/nodejs/node/pull/5929" target="_blank" rel="noopener">#5929</a></li>
</ul>
</li>
</ul>
<h3 id="dns"><a href="#dns" class="headerlink" title="dns"></a>dns</h3><p>[<a href="https://nodejs.org/dist/latest-v6.x/docs/api/dns.html" target="_blank" rel="noopener">Docs</a>]</p>
<ul>
<li><a href="https://nodejs.org/dist/latest-v6.x/docs/api/dns.html#dns_dns_resolve_hostname_rrtype_callback" target="_blank" rel="noopener"><code>dns.resolve()</code></a>现在支持解析纯DNS PTR记录。<ul>
<li>之前,调用<code>dns.resolve(hostname, 'PTR', cb)</code>会调用<code>dns.reverse()</code>,之后不再这样。</li>
<li>现在hostname必须传入反转的 <em>IN-ADDR</em> 域。</li>
<li>Refs: <a href="https://github.com/nodejs/node/commit/dbdbdd4998" target="_blank" rel="noopener"><code>dbdbdd4998</code></a>, <a href="https://github.com/nodejs/node/pull/4921" target="_blank" rel="noopener">#4921</a></li>
</ul>
</li>
</ul>
<p>Before:</p>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line">dns.resolve(<span class="string">'8.8.4.4'</span>, <span class="string">'PTR'</span>, (err, result) => {</span><br><span class="line"> <span class="keyword">if</span> (err) {</span><br><span class="line"> <span class="comment">// handle error</span></span><br><span class="line"> }</span><br><span class="line"> <span class="comment">// result => ['google-public-dns-b.google.com']</span></span><br><span class="line">});</span><br></pre></td></tr></table></figure>
<p>After:</p>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line">dns.resolve(<span class="string">'4.4.8.8-in-addr.arpa'</span>, <span class="string">'PTR'</span>, (err, result) => {</span><br><span class="line"> <span class="keyword">if</span> (err) {</span><br><span class="line"> <span class="comment">// handle error</span></span><br><span class="line"> }</span><br><span class="line"> <span class="comment">// result => ['google-public-dns-b.google.com']</span></span><br><span class="line">});</span><br><span class="line"></span><br><span class="line"><span class="comment">// one could also simply do</span></span><br><span class="line">dns.reverse(<span class="string">'8.8.4.4'</span>, (err, result) => {</span><br><span class="line"> <span class="keyword">if</span> (err) {</span><br><span class="line"> <span class="comment">// handle error</span></span><br><span class="line"> }</span><br><span class="line"> <span class="comment">// result => ['google-public-dns-b.google.com']</span></span><br><span class="line">});</span><br></pre></td></tr></table></figure>
<ul>
<li><a href="https://nodejs.org/dist/latest-v6.x/docs/api/dns.html#dns_dns_lookupservice_address_port_callback" target="_blank" rel="noopener"><code>dns.lookupService()</code></a>现在将port参数强制转换为数字。<ul>
<li>之前,如果<code>port</code>不是数字会抛出<code>TypeError</code>。</li>
<li>现在,如果port不在 0-65535 范围内的话会抛出<code>TypeError</code>。</li>
<li>Refs: <a href="https://github.com/nodejs/node/commit/f3be421c1c" target="_blank" rel="noopener"><code>f3be421c1c</code></a>, <a href="https://github.com/nodejs/node/pull/4883" target="_blank" rel="noopener">#4883</a></li>
</ul>
</li>
</ul>
<h3 id="domain"><a href="#domain" class="headerlink" title="domain"></a>domain</h3><p>[<a href="https://nodejs.org/dist/latest-v6.x/docs/api/domain.html" target="_blank" rel="noopener">Docs</a>]</p>
<ul>
<li>如果没有domain <code>error</code>事件处理程序,domains不再将上下文指派给其他错误处理程序。<ul>
<li>之前只有在domain的<code>error</code>事件被处理的情况下才这样处理。</li>
<li>Refs: <a href="https://github.com/nodejs/node/commit/90204cc468" target="_blank" rel="noopener"><code>90204cc468</code></a>, <a href="https://github.com/nodejs/node/pull/4659" target="_blank" rel="noopener">#4659</a></li>
</ul>
</li>
</ul>
<h3 id="events"><a href="#events" class="headerlink" title="events"></a>events</h3><p>[<a href="https://nodejs.org/dist/latest-v6.x/docs/api/events.html" target="_blank" rel="noopener">Docs</a>]</p>
<ul>
<li>内部事件处理程序的存储对象<code>EventEmitter#_events</code>现在继承自<code>Object.create(null)</code>而不是<code>Object.prototype</code>。<ul>
<li>这样避免了使用原本保留的属性名时的问题,例如:<code>__proto__</code>。</li>
<li>这也意味着,模块有意添加在<code>Object.prototype</code>上的所有属性在<code>_events</code>中都不可用。</li>
<li>Refs: <a href="https://github.com/nodejs/node/commit/e38bade828" target="_blank" rel="noopener"><code>e38bade828</code></a>, <a href="https://github.com/nodejs/node/pull/6092" target="_blank" rel="noopener">#6092</a></li>
</ul>
</li>
</ul>
<h3 id="freelist"><a href="#freelist" class="headerlink" title="freelist"></a>freelist</h3><ul>
<li>移除弃用的<code>freelist</code>模块。<ul>
<li>这个模块主要用于内部使用,我们没有维护它的打算。</li>
<li>如有需要使用他人的模块会更合适。</li>
<li>Refs: <a href="https://github.com/nodejs/node/commit/b70dc67828" target="_blank" rel="noopener"><code>b70dc67828</code></a>, <a href="https://github.com/nodejs/node/pull/3738" target="_blank" rel="noopener">#3738</a></li>
</ul>
</li>
</ul>
<h3 id="fs"><a href="#fs" class="headerlink" title="fs"></a>fs</h3><p>[<a href="https://nodejs.org/dist/latest-v6.x/docs/api/fs.html" target="_blank" rel="noopener">Docs</a>]</p>
<ul>
<li><a href="https://nodejs.org/dist/latest-v6.x/docs/api/fs.html#fs_fs_readdir_path_options_callback" target="_blank" rel="noopener"><code>fs.readdir{Sync}()</code></a>现在默认返回utf8编码的文件名。<ul>
<li>文件名的编码现在通过一个选项来配置。</li>
<li>Example: <code>fs.readdir(path, { encoding: 'hex' }, callback)</code></li>
<li>Refs: <a href="https://github.com/nodejs/node/commit/060e5f0c00" target="_blank" rel="noopener"><code>060e5f0c00</code></a>, <a href="https://github.com/nodejs/node/pull/5616" target="_blank" rel="noopener">#5616</a></li>
</ul>
</li>
<li>弃用重新评估用户代码中的<code>fs</code>源码。(译者注:这句不知道怎么翻译才好。原文:Deprecated re-evaluating the fs source code from user code.)<ul>
<li>Refs: <a href="https://github.com/nodejs/node/commit/1d79787e2e" target="_blank" rel="noopener"><code>1d79787e2e</code></a>, <a href="https://github.com/nodejs/node/pull/5102" target="_blank" rel="noopener">#5102</a></li>
</ul>
</li>
<li>弃用<a href="https://nodejs.org/dist/latest-v6.x/docs/api/fs.html#fs_fs_read_fd_buffer_offset_length_position_callback" target="_blank" rel="noopener"><code>fs.read()</code></a>遗留的<code>(fd, length, position, encoding, callback)</code>调用方式。<ul>
<li>Refs: <a href="https://github.com/nodejs/node/commit/1124de2d76" target="_blank" rel="noopener"><code>1124de2d76</code></a>, <a href="https://github.com/nodejs/node/pull/4525" target="_blank" rel="noopener">#4525</a></li>
</ul>
</li>
<li><code>fs.read()</code>读长为0时不再抛出异常。(译者注:接收数据的buffer长度为0。)<ul>
<li>Refs: <a href="https://github.com/nodejs/node/commit/2b15e68bbe" target="_blank" rel="noopener"><code>2b15e68bbe</code></a>, <a href="https://github.com/nodejs/node/pull/4518" target="_blank" rel="noopener">#4518</a></li>
</ul>
</li>
<li><a href="https://nodejs.org/dist/latest-v6.x/docs/api/fs.html#fs_fs_link_srcpath_dstpath_callback" target="_blank" rel="noopener"><code>fs.link{Sync}()</code></a>现在按照正确的顺序检查调用参数。<ul>
<li>Refs: <a href="https://github.com/nodejs/node/commit/8b97249893" target="_blank" rel="noopener"><code>8b97249893</code></a>, <a href="https://github.com/nodejs/node/pull/3917" target="_blank" rel="noopener">#3917</a></li>
</ul>
</li>
<li><a href="https://nodejs.org/dist/latest-v6.x/docs/api/fs.html#fs_fs_realpath_path_options_callback" target="_blank" rel="noopener"><code>fs.realpath{Sync}()</code></a>现在内部使用<code>uv_fs_realpath()</code>而不是JavaScript实现.<ul>
<li><code>cache</code>参数不再接受对象作为缓存,并且被<code>options</code>参数替代。</li>
<li>Refs: <a href="https://github.com/nodejs/node/commit/b488b19eaf" target="_blank" rel="noopener"><code>b488b19eaf</code></a>, <a href="https://github.com/nodejs/node/pull/3594" target="_blank" rel="noopener">#3594</a></li>
</ul>
</li>
</ul>
<h3 id="globals"><a href="#globals" class="headerlink" title="globals"></a>globals</h3><p>[<a href="https://nodejs.org/dist/latest-v6.x/docs/api/globals.html" target="_blank" rel="noopener">Docs</a>]</p>
<ul>
<li>弃用<a href="https://nodejs.org/dist/latest-v6.x/docs/api/globals.html#globals_global" target="_blank" rel="noopener"><code>global</code></a>的别名<code>root</code>和<code>GLOBAL</code>。<ul>
<li>Refs: <a href="https://github.com/nodejs/node/commit/4e46931406" target="_blank" rel="noopener"><code>4e46931406</code></a>, <a href="https://github.com/nodejs/node/pull/1838" target="_blank" rel="noopener">#1838</a></li>
</ul>
</li>
</ul>
<h3 id="module"><a href="#module" class="headerlink" title="module"></a>module</h3><p>[<a href="https://nodejs.org/dist/latest-v6.x/docs/api/modules.html" target="_blank" rel="noopener">Docs</a>]</p>
<ul>
<li>现在在相对查找时优先查找当前目录。<ul>
<li>之前如果<code>node_module</code>目录存在会优先查找<code>node_module</code>目录。</li>
<li>例如,之前如果<code>node_modules/example</code>存在,<code>require('./example')</code>会优先加载<code>node_modules/example</code>而不是<code>./example.js</code>。</li>
<li>Refs: <a href="https://github.com/nodejs/node/commit/d38503ab01" target="_blank" rel="noopener"><code>d38503ab01</code></a>, <a href="https://github.com/nodejs/node/pull/5689" target="_blank" rel="noopener">#5689</a></li>
</ul>
</li>
<li>现在使用<a href="https://nodejs.org/dist/latest-v6.x/docs/api/globals.html#globals_require" target="_blank" rel="noopener"><code>require()</code></a>时符号链接会被保留。<ul>
<li>Refs: <a href="https://github.com/nodejs/node/commit/de1dc0ae2e" target="_blank" rel="noopener"><code>de1dc0ae2e</code></a>, <a href="https://github.com/nodejs/node/pull/5950" target="_blank" rel="noopener">#5950</a>.</li>
</ul>
</li>
<li><code>require()</code>的文件中的语法错误现在会打印更多信息。<ul>
<li>Refs: <a href="https://github.com/nodejs/node/commit/18490d3d5a" target="_blank" rel="noopener"><code>18490d3d5a</code></a>, <a href="https://github.com/nodejs/node/pull/4287" target="_blank" rel="noopener">#4287</a></li>
</ul>
</li>
</ul>
<h3 id="net"><a href="#net" class="headerlink" title="net"></a>net</h3><p>[<a href="https://nodejs.org/dist/latest-v6.x/docs/api/net.html" target="_blank" rel="noopener">Docs</a>]</p>
<ul>
<li>现在检查端口有效时更严谨。<ul>
<li>现在保证像<code>true</code>和<code>[1]</code>等值不被视为有效的端口。</li>
<li>Refs: <a href="https://github.com/nodejs/node/commit/d0edabecbf" target="_blank" rel="noopener"><code>d0edabecbf</code></a>, <a href="https://github.com/nodejs/node/pull/5733" target="_blank" rel="noopener">#5733</a>, <a href="https://github.com/nodejs/node/commit/02ac302b6d" target="_blank" rel="noopener"><code>02ac302b6d</code></a>, <a href="https://github.com/nodejs/node/pull/5732" target="_blank" rel="noopener">#5732</a></li>
</ul>
</li>
<li><a href="https://nodejs.org/dist/latest-v6.x/docs/api/net.html#net_net_createserver_options_connectionlistener" target="_blank" rel="noopener"><code>net.createServer()</code></a>现在当提供的<code>options</code>参数不是对象时会抛出异常。<ul>
<li>仍然可以只提供一个connectionListener回调函数。</li>
<li>Refs: <a href="https://github.com/nodejs/node/commit/a78b3344f8" target="_blank" rel="noopener"><code>a78b3344f8</code></a>, <a href="https://github.com/nodejs/node/pull/2904" target="_blank" rel="noopener">#2904</a></li>
</ul>
</li>
<li><code>V4MAPPED</code> DNS hint不再默认设置,但<code>ADDRCONFIG</code>仍然会默认设置。<ul>
<li>如果你的平台需要设置hints,可以使用<a href="https://nodejs.org/dist/latest-v6.x/docs/api/net.html#net_socket_connect_options_connectlistener" target="_blank" rel="noopener"><code>Socket#connect()</code></a>中新的选项<code>hints</code>。</li>
<li>Refs: <a href="https://github.com/nodejs/node/commit/b85a50b6da" target="_blank" rel="noopener"><code>b85a50b6da</code></a>, <a href="https://github.com/nodejs/node/pull/6021" target="_blank" rel="noopener">#6021</a></li>
</ul>
</li>
</ul>
<h3 id="path"><a href="#path" class="headerlink" title="path"></a>path</h3><p>[<a href="https://nodejs.org/dist/latest-v6.x/docs/api/path.html" target="_blank" rel="noopener">Docs</a>]</p>
<ul>
<li>如果提供的输入不是string类型的话,所有path模块的方法都会抛出异常。<ul>
<li>Refs: <a href="https://github.com/nodejs/node/commit/08085c49b6" target="_blank" rel="noopener"><code>08085c49b6</code></a>, <a href="https://github.com/nodejs/node/pull/5348" target="_blank" rel="noopener">#5348</a></li>
</ul>
</li>
<li>现在<a href="https://nodejs.org/dist/latest-v6.x/docs/api/path.html#path_path_format_pathobject" target="_blank" rel="noopener"><code>path.format()</code></a>在不同平台更一致且更实用。<ul>
<li>Refs: <a href="https://github.com/nodejs/node/commit/d1000b4137" target="_blank" rel="noopener"><code>d1000b4137</code></a>, <a href="https://github.com/nodejs/node/pull/2408" target="_blank" rel="noopener">#2408</a></li>
</ul>
</li>
</ul>
<h3 id="process"><a href="#process" class="headerlink" title="process"></a>process</h3><p>[<a href="https://nodejs.org/dist/latest-v6.x/docs/api/process.html" target="_blank" rel="noopener">Docs</a>]</p>
<ul>
<li>现在使用<code>process.EventEmitter</code>会打印弃用警告。<ul>
<li>该方法已经在源码中弃用很长时间。</li>
<li>Refs: <a href="https://github.com/nodejs/node/commit/25751bedfe" target="_blank" rel="noopener"><code>25751bedfe</code></a>, <a href="https://github.com/nodejs/node/pull/5049" target="_blank" rel="noopener">#5049</a></li>
</ul>
</li>
<li>所有之前打印的node警告行为更加一致,现在只通过默认的处理程序发出process <a href="https://nodejs.org/dist/latest-v6.x/docs/api/process.html#process_event_warning" target="_blank" rel="noopener"><code>'warning'</code></a>事件。<ul>
<li>包括弃用警告,现在被归类为<code>DeprecationWarning</code>.</li>
<li>Refs: <a href="https://github.com/nodejs/node/commit/c6656db352" target="_blank" rel="noopener"><code>c6656db352</code></a>, <a href="https://github.com/nodejs/node/pull/4782" target="_blank" rel="noopener">#4782</a></li>
</ul>
</li>
<li>现在如果<a href="https://nodejs.org/dist/latest-v6.x/docs/api/process.html#process_process_nexttick_callback_arg" target="_blank" rel="noopener"><code>process.nextTick()</code></a>的参数不是function的话会抛出异常。<ul>
<li>Refs: <a href="https://github.com/nodejs/node/commit/72e3dd9f43" target="_blank" rel="noopener"><code>72e3dd9f43</code></a>, <a href="https://github.com/nodejs/node/pull/3860" target="_blank" rel="noopener">#3860</a></li>
</ul>
</li>
</ul>
<h3 id="querystring"><a href="#querystring" class="headerlink" title="querystring"></a>querystring</h3><p>[<a href="https://nodejs.org/dist/latest-v6.x/docs/api/querystring.html" target="_blank" rel="noopener">Docs</a>]</p>
<ul>
<li><a href="https://nodejs.org/dist/latest-v6.x/docs/api/querystring.html#querystring_querystring_parse_str_sep_eq_options" target="_blank" rel="noopener"><code>querystring.parse()</code></a>返回的解析后的对象现在继承自<code>Object.create(null)</code>而不是<code>Object.prototype</code>。<ul>
<li>这样避免了使用原本保留的属性名时的问题,例如:<code>__proto__</code>。</li>
<li>这也意味着,模块有意添加在<code>Object.prototype</code>上的所有属性在返回的对象中都不可用。</li>
<li>Refs: <a href="https://github.com/nodejs/node/commit/dba245f796" target="_blank" rel="noopener"><code>dba245f796</code></a>, <a href="https://github.com/nodejs/node/pull/6055" target="_blank" rel="noopener">#6055</a></li>
</ul>
</li>
<li><a href="https://nodejs.org/dist/latest-v6.x/docs/api/querystring.html#querystring_querystring_escape" target="_blank" rel="noopener"><code>querystring.escape()</code></a>现在对于对象使用<code>Object#toString()</code>而不是<code>Object#valueOf()</code>。<ul>
<li>这样使得它与<code>encodeURIComponent()</code>的功能更加一致。</li>
<li><a href="https://github.com/nodejs/node/commit/5dafb435d8" target="_blank" rel="noopener"><code>5dafb435d8</code></a>, <a href="https://github.com/nodejs/node/pull/5341" target="_blank" rel="noopener">#5341</a></li>
</ul>
</li>
</ul>
<h3 id="readline"><a href="#readline" class="headerlink" title="readline"></a>readline</h3><p>[<a href="https://nodejs.org/dist/latest-v6.x/docs/api/readline.html" target="_blank" rel="noopener">Docs</a>]</p>
<ul>
<li>Readline的历史现在可以通过设置<a href="https://nodejs.org/dist/latest-v6.x/docs/api/readline.html#readline_readline_createinterface_options" target="_blank" rel="noopener"><code>createInterface()</code></a>的选项<code>historySize</code>为<code>0</code>来禁用。<ul>
<li>之前将之设置为<code>0</code>会使用默认的<code>30</code>行。</li>
<li>Refs: <a href="https://github.com/nodejs/node/commit/0303a2552e" target="_blank" rel="noopener"><code>0303a2552e</code></a>, <a href="https://github.com/nodejs/node/pull/6352" target="_blank" rel="noopener">#6352</a></li>
</ul>
</li>
<li>不建议使用下面这些不在文档中的readline函数,它们仅用于内部使用:<ul>
<li><code>isFullWidthCodePoint()</code>, <code>stripVTControlCharacters()</code>, <code>getStringWidth()</code>, <code>emitKeys()</code></li>
<li>Refs: <a href="https://github.com/nodejs/node/commit/ca2e8b292f" target="_blank" rel="noopener"><code>ca2e8b292f</code></a>, <a href="https://github.com/nodejs/node/pull/3862" target="_blank" rel="noopener">#3862</a></li>
</ul>
</li>
<li><a href="https://nodejs.org/dist/latest-v6.x/docs/api/readline.html#readline_readline_emitkeypressevents_stream" target="_blank" rel="noopener"><code>Readline#emitKeypressEvents(stream)</code></a>现在总是向提供的stream的<code>'keypress'</code>事件传入按键信息。<ul>
<li>Refs: <a href="https://github.com/nodejs/node/commit/0a62f929da" target="_blank" rel="noopener"><code>0a62f929da</code></a>, <a href="https://github.com/nodejs/node/pull/6024" target="_blank" rel="noopener">#6024</a></li>
</ul>
</li>
</ul>
<h3 id="repl"><a href="#repl" class="headerlink" title="repl"></a>repl</h3><p>[<a href="https://nodejs.org/dist/latest-v6.x/docs/api/repl.html" target="_blank" rel="noopener">Docs</a>]</p>
<ul>
<li>现在可以向<code>_</code>赋值,<code>_</code>通常保存REPL中最后一个表达式的结果。<ul>
<li>这样做将会打印一条警告并禁用保存最后一个表达式的结果。</li>
<li>Refs: <a href="https://github.com/nodejs/node/commit/ad8257fa5b" target="_blank" rel="noopener"><code>ad8257fa5b</code></a>, <a href="https://github.com/nodejs/node/pull/5535" target="_blank" rel="noopener">5535</a></li>
</ul>
</li>
<li>做了一些改进减少当REPL执行失败时的错误数量。<ul>
<li>Refs: <a href="https://github.com/nodejs/node/commit/3ee68f794f" target="_blank" rel="noopener"><code>3ee68f794f</code></a>, <a href="https://github.com/nodejs/node/pull/6328" target="_blank" rel="noopener">6328</a></li>
</ul>
</li>
</ul>
<h3 id="stream"><a href="#stream" class="headerlink" title="stream"></a>stream</h3><p>[<a href="https://nodejs.org/dist/latest-v6.x/docs/api/stream.html" target="_blank" rel="noopener">Docs</a>]</p>
<ul>
<li>在使用<a href="https://nodejs.org/dist/latest-v6.x/docs/api/stream.html#stream_object_mode" target="_blank" rel="noopener">object mode</a>时<a href="https://nodejs.org/dist/latest-v6.x/docs/api/stream.html#stream_writable_write_chunk_encoding_callback" target="_blank" rel="noopener">写入</a>一个<code>null</code>块现在是无效的,将会抛出<code>TypeError</code>。<ul>
<li>Refs: <a href="https://github.com/nodejs/node/commit/e7c077c610" target="_blank" rel="noopener"><code>e7c077c610</code></a>, <a href="https://github.com/nodejs/node/pull/6170" target="_blank" rel="noopener">#6170</a></li>
</ul>
</li>
</ul>
<h3 id="timers"><a href="#timers" class="headerlink" title="timers"></a>timers</h3><p>[<a href="https://nodejs.org/dist/latest-v6.x/docs/api/timers.html" target="_blank" rel="noopener">Docs</a>]</p>
<ul>
<li>如果没有向提供<code>set{</code><a href="https://nodejs.org/dist/latest-v6.x/docs/api/timers.html#timers_settimeout_callback_delay_arg" target="_blank" rel="noopener"><code>Timeout</code></a><code>|</code><a href="https://nodejs.org/dist/latest-v6.x/docs/api/timers.html#timers_setinterval_callback_delay_arg" target="_blank" rel="noopener"><code>Interval</code></a><code>|</code><a href="https://nodejs.org/dist/latest-v6.x/docs/api/timers.html#timers_setimmediate_callback_arg" target="_blank" rel="noopener"><code>Immediate</code></a><code>}()</code>函数将会立刻抛出异常。<ul>
<li>这些方法之前也会抛出异常,但是是在时间到时抛出。</li>
<li>Refs: <a href="https://github.com/nodejs/node/commit/ac153bd2a6" target="_blank" rel="noopener"><code>ac153bd2a6</code></a>, <a href="https://github.com/nodejs/node/pull/4362" target="_blank" rel="noopener">#4362</a></li>
</ul>
</li>
</ul>
<h3 id="tls"><a href="#tls" class="headerlink" title="tls"></a>tls</h3><p>[<a href="https://nodejs.org/dist/latest-v6.x/docs/api/tls.html" target="_blank" rel="noopener">Docs</a>]</p>
<ul>
<li><a href="https://nodejs.org/dist/latest-v6.x/docs/api/tls.html#tls_class_tls_server" target="_blank" rel="noopener"><code>tls.Server</code></a>的<code>'clientError'</code>修改为<a href="https://nodejs.org/dist/latest-v6.x/docs/api/tls.html#tls_event_tlsclienterror" target="_blank" rel="noopener"><code>'tlsClientError'</code></a>。<ul>
<li>因为T<code>http</code>现在有<a href="https://nodejs.org/dist/latest-v6.x/docs/api/http.html#http_event_clienterror" target="_blank" rel="noopener"><code>'clientError'</code></a>。</li>
<li>Refs: <a href="https://github.com/nodejs/node/commit/1ab6b21360" target="_blank" rel="noopener"><code>1ab6b21360</code></a>, <a href="https://github.com/nodejs/node/pull/4557" target="_blank" rel="noopener">#4557</a></li>
</ul>
</li>
<li><a href="https://nodejs.org/dist/latest-v6.x/docs/api/tls.html#tls_tls_createserver_options_secureconnectionlistener" target="_blank" rel="noopener"><code>tls.createServer()</code></a>‘s <code>sessionIdContext</code>现在默认使用sha1代替md5进行hash.<ul>
<li>仅适用于<code>sessionIdContext</code>没有手动设置并且<code>requestCert</code>设置为<code>true</code>。</li>
<li>Refs: <a href="https://github.com/nodejs/node/commit/df268f97bc" target="_blank" rel="noopener"><code>df268f97bc</code></a>, <a href="https://github.com/nodejs/node/pull/3866" target="_blank" rel="noopener">#3866</a></li>
</ul>
</li>
<li>在文档中弃用<a href="https://nodejs.org/dist/latest-v6.x/docs/api/tls.html#tls_tls_createsecurepair_context_isserver_requestcert_rejectunauthorized_options" target="_blank" rel="noopener"><code>tls.createSecurePair()</code></a>并使用<a href="https://nodejs.org/dist/latest-v6.x/docs/api/tls.html#tls_class_tls_tlssocket" target="_blank" rel="noopener"><code>TLSSocket</code></a>替代。<ul>
<li>Refs: <a href="https://github.com/nodejs/node/commit/31de5cc436" target="_blank" rel="noopener"><code>31de5cc436</code></a>, <a href="https://github.com/nodejs/node/pull/6063" target="_blank" rel="noopener">#6063</a></li>
</ul>
</li>
</ul>
<h3 id="tty"><a href="#tty" class="headerlink" title="tty"></a>tty</h3><p>[<a href="https://nodejs.org/dist/latest-v6.x/docs/api/tty.html" target="_blank" rel="noopener">Docs</a>]</p>
<ul>
<li>移除之前弃用的全局方法<code>tty.setRawMode()</code>。<ul>
<li>使用<a href="https://nodejs.org/dist/latest-v6.x/docs/api/tty.html#tty_rs_setrawmode_mode" target="_blank" rel="noopener">tty instance method</a>替代。</li>
<li>Refs: <a href="https://github.com/nodejs/node/commit/a2c0aa84e0" target="_blank" rel="noopener"><code>a2c0aa84e0</code></a>, <a href="https://github.com/nodejs/node/pull/2528" target="_blank" rel="noopener">#2528</a></li>
</ul>
</li>
</ul>
<h3 id="url"><a href="#url" class="headerlink" title="url"></a>url</h3><p>[<a href="https://nodejs.org/dist/latest-v6.x/docs/api/url.html" target="_blank" rel="noopener">Docs</a>]</p>
<ul>
<li>现在如果host改变,<a href="https://nodejs.org/dist/latest-v6.x/docs/api/url.html#url_url_resolve_from_to" target="_blank" rel="noopener"><code>url.resolve()</code></a>将清除认证信息。<ul>
<li>这是一种安全措施,以确保身份验证凭据不会泄露。</li>
<li>Refs: <a href="https://github.com/nodejs/node/commit/eb4201f07a" target="_blank" rel="noopener"><code>eb4201f07a</code></a>, <a href="https://github.com/nodejs/node/pull/1480" target="_blank" rel="noopener">#1480</a></li>
</ul>
</li>
</ul>
<h3 id="util"><a href="#util" class="headerlink" title="util"></a>util</h3><p>[<a href="https://nodejs.org/dist/latest-v6.x/docs/api/util.html" target="_blank" rel="noopener">Docs</a>]</p>
<ul>
<li>Error子类现在被格式化为<code>[MyError: message]</code>而不是<code>MyError {}</code>。<ul>
<li>Refs: <a href="https://github.com/nodejs/node/commit/e2f47f5698" target="_blank" rel="noopener"><code>e2f47f5698</code></a>, <a href="https://github.com/nodejs/node/pull/4582" target="_blank" rel="noopener">#4582</a></li>
</ul>
</li>
<li><code>Date</code>现在总是使用<code>Date#toISOString()</code>来格式化。<ul>
<li>Refs: <a href="https://github.com/nodejs/node/commit/93d6b5fb68" target="_blank" rel="noopener"><code>93d6b5fb68</code></a>, <a href="https://github.com/nodejs/node/pull/4318" target="_blank" rel="noopener">#4318</a></li>
</ul>
</li>
<li><a href="https://nodejs.org/dist/latest-v6.x/docs/api/util.html#util_util_inspect_object_options" target="_blank" rel="noopener"><code>util.inspect()</code></a>现在使用c++ bindings检测。<ul>
<li>Refs: <a href="https://github.com/nodejs/node/commit/24012a879d" target="_blank" rel="noopener"><code>24012a879d</code></a>, <a href="https://github.com/nodejs/node/pull/4098" target="_blank" rel="noopener">#4098</a></li>
</ul>
</li>
<li>移除之前弃用的<code>util.pump()</code>,请使用<a href="https://nodejs.org/dist/latest-v6.x/docs/api/stream.html#stream_readable_pipe_destination_options" target="_blank" rel="noopener"><code>ReadableStream#pipe()</code></a>替代。<ul>
<li>Refs: <a href="https://github.com/nodejs/node/commit/007cfea308" target="_blank" rel="noopener"><code>007cfea308</code></a>, <a href="https://github.com/nodejs/node/pull/2531" target="_blank" rel="noopener">#2531</a></li>
</ul>
</li>
<li>移除之前弃用的<code>util.exec()</code>,请使用<a href="https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_child_process_exec_command_options_callback" target="_blank" rel="noopener"><code>child_process.exec()</code></a>替代。<ul>
<li>Refs: <a href="https://github.com/nodejs/node/commit/4cf19ad1bb" target="_blank" rel="noopener"><code>4cf19ad1bb</code></a>, <a href="https://github.com/nodejs/node/pull/2530" target="_blank" rel="noopener">#2530</a></li>
</ul>
</li>
<li>TypedArrays格式化现在与普通数组一样。<ul>
<li>同样适用于ArrayBuffer和DataView。</li>
<li>Refs: <a href="https://github.com/nodejs/node/commit/34a35919e1" target="_blank" rel="noopener"><code>34a35919e1</code></a>, <a href="https://github.com/nodejs/node/pull/3793" target="_blank" rel="noopener">#3793</a></li>
</ul>
</li>
<li>弃用<a href="https://nodejs.org/dist/latest-v6.x/docs/api/util.html#util_util_extend_obj" target="_blank" rel="noopener"><code>util._extend()</code></a>并由<a href="https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign" target="_blank" rel="noopener"><code>Object.assign()</code></a>替代。<ul>
<li>Refs: <a href="https://github.com/nodejs/node/commit/d8290286b3" target="_blank" rel="noopener"><code>d8290286b3</code></a>, <a href="https://github.com/nodejs/node/pull/4903" target="_blank" rel="noopener">#4903</a></li>
</ul>
</li>
<li><a href="https://nodejs.org/dist/latest-v6.x/docs/api/util.html#util_util_log_string" target="_blank" rel="noopener"><code>util.log()</code></a>在文档中给出弃用警告。<ul>
<li>Refs: <a href="https://github.com/nodejs/node/commit/236b7e8dd1" target="_blank" rel="noopener"><code>236b7e8dd1</code></a>, <a href="https://github.com/nodejs/node/pull/6161" target="_blank" rel="noopener">#6161</a></li>
</ul>
</li>
</ul>
<h3 id="vm"><a href="#vm" class="headerlink" title="vm"></a>vm</h3><p>[<a href="https://nodejs.org/dist/latest-v6.x/docs/api/vm.html" target="_blank" rel="noopener">Docs</a>]</p>
<ul>
<li><a href="https://nodejs.org/dist/latest-v6.x/docs/api/vm.html#vm_class_script" target="_blank" rel="noopener"><code>vm.Script</code></a>的<code>displayErrors</code>选项现在错误堆栈附加导致错误的代码行。<ul>
<li>Refs: <a href="https://github.com/nodejs/node/commit/57003520f8" target="_blank" rel="noopener"><code>57003520f8</code></a>, <a href="https://github.com/nodejs/node/pull/4874" target="_blank" rel="noopener">#4874</a></li>
</ul>
</li>
</ul>
<h3 id="zlib"><a href="#zlib" class="headerlink" title="zlib"></a>zlib</h3><p>[<a href="https://nodejs.org/dist/latest-v6.x/docs/api/zlib.html" target="_blank" rel="noopener">Docs</a>]</p>
<ul>
<li>zlib实例的<code>close</code>事件不再在同步调用中发出。<ul>
<li>只会影响所有的<code>*Sync()</code>方法。</li>
<li>Refs: <a href="https://github.com/nodejs/node/commit/8b43d3f52d" target="_blank" rel="noopener"><code>8b43d3f52d</code></a>, <a href="https://github.com/nodejs/node/pull/5707" target="_blank" rel="noopener">#5707</a></li>
</ul>
</li>
<li>Gzip流的尾随垃圾不再丢弃,现在会抛出错误。<ul>
<li>注意:空字节田中不受影响,因为诸多场合已经指出这种填充是正常的,会被<code>gzip(1)</code>丢弃。</li>
<li>Refs: <a href="https://github.com/nodejs/node/commit/54a5287e3e" target="_blank" rel="noopener"><code>54a5287e3e</code></a>, <a href="https://github.com/nodejs/node/pull/5883" target="_blank" rel="noopener">#5883</a></li>
</ul>
</li>
</ul>
<h2 id="Native-Modules-Addons"><a href="#Native-Modules-Addons" class="headerlink" title="Native Modules (Addons)"></a>Native Modules (Addons)</h2><ul>
<li>ABI模块由于一个模块初始化的次版本增加已经改变。<ul>
<li>这仅仅意味着原生插件需要重新编译。</li>
<li>Refs: <a href="https://github.com/nodejs/node/commit/71470a8e45" target="_blank" rel="noopener"><code>71470a8e45</code></a>, <a href="https://github.com/nodejs/node/pull/4771" target="_blank" rel="noopener">#4771</a></li>
</ul>
</li>
<li><code>NODE_MODULE_VERSION</code>现在是<code>48</code>。</li>
<li>移除一些之前弃用的内部函数。<ul>
<li>Refs: <a href="https://github.com/nodejs/node/commit/757fbac64b" target="_blank" rel="noopener"><code>757fbac64b</code></a>, <a href="https://github.com/nodejs/node/pull/6053" target="_blank" rel="noopener">#6053</a></li>
</ul>
</li>
</ul>
<h2 id="General-Node"><a href="#General-Node" class="headerlink" title="General Node"></a>General Node</h2><ul>
<li>内部工具不再打入node包中,减少了大约10%的体积。<ul>
<li>Refs: <a href="https://github.com/nodejs/node/commit/90a5fc20be" target="_blank" rel="noopener"><code>90a5fc20be</code></a>, <a href="https://github.com/nodejs/node/pull/5695" target="_blank" rel="noopener">#5695</a></li>
</ul>
</li>
<li>现在打印的所有警告以<code>(node:pid)</code>开头。<ul>
<li>Refs: <a href="https://github.com/nodejs/node/commit/d01eb6882f" target="_blank" rel="noopener"><code>d01eb6882f</code></a>, <a href="https://github.com/nodejs/node/pull/3878" target="_blank" rel="noopener">#3878</a>, <a href="https://github.com/nodejs/node/commit/94b9948d63" target="_blank" rel="noopener"><code>94b9948d63</code></a>, <a href="https://github.com/nodejs/node/pull/3833" target="_blank" rel="noopener">#3833</a></li>
</ul>
</li>
<li>现在所有模块的错误消息更加一致。<ul>
<li>全部由大写字母开头,除此之外不含存在大写字母的普通单词,不含结尾标识。</li>
<li>另外,参数名和其他代码现在总是被双引号(<code>\"</code>)包围。</li>
<li>某些情况下,错误会提供更多信息。</li>
<li>Refs: <a href="https://github.com/nodejs/node/commit/20285ad177" target="_blank" rel="noopener"><code>20285ad177</code></a>, <a href="https://github.com/nodejs/node/pull/3374" target="_blank" rel="noopener">#3374</a>, <a href="https://github.com/nodejs/node/commit/53a95a5b12" target="_blank" rel="noopener"><code>53a95a5b12</code></a>, <a href="https://github.com/nodejs/node/pull/5616" target="_blank" rel="noopener">#5616</a>, <a href="https://github.com/nodejs/node/commit/8bb60e3c8d" target="_blank" rel="noopener"><code>8bb60e3c8d</code></a>, <a href="https://github.com/nodejs/node/pull/5590" target="_blank" rel="noopener">#5590</a>, <a href="https://github.com/nodejs/node/commit/ec49fc8229" target="_blank" rel="noopener"><code>ec49fc8229</code></a>, <a href="https://github.com/nodejs/node/pull/5981" target="_blank" rel="noopener">#5981</a></li>
</ul>
</li>
<li>Node.js不再支持Windows Vista和之前的版本,不会在这些版本上运行。<ul>
<li>另外,安装程序在这些系统上不会安装。</li>
<li>现在支持的windows最低版本是Windows 7和Windows Server 2008 R2。</li>
<li>Refs: <a href="https://github.com/nodejs/node/commit/1cf26c036d" target="_blank" rel="noopener"><code>1cf26c036d</code></a>, <a href="https://github.com/nodejs/node/commit/55db19074d" target="_blank" rel="noopener"><code>55db19074d</code></a>, <a href="https://github.com/nodejs/node/pull/5167" target="_blank" rel="noopener">#5167</a></li>
</ul>
</li>
<li>Node.js不再支持OS X 10.7一下版本。<ul>
<li>Refs: <a href="https://github.com/nodejs/node/commit/204f3a8a0b" target="_blank" rel="noopener"><code>204f3a8a0b</code></a>, <a href="https://github.com/nodejs/node/pull/6402" target="_blank" rel="noopener">#6402</a></li>
</ul>
</li>
<li>通过<code>Makefile</code> (<code>tools/install.py</code>)安装不再尝试改变npm的shebang中的node目标路径为本地构建的路径。<ul>
<li>保持其为<code>#!/usr/bin/env node</code>,即在全局查找node。</li>
<li>Refs: <a href="https://github.com/nodejs/node/commit/8ffa20c495" target="_blank" rel="noopener"><code>8ffa20c495</code></a>, <a href="https://github.com/nodejs/node/pull/6098" target="_blank" rel="noopener">#6098</a></li>
</ul>
</li>
</ul>
<h2 id="Dependencies"><a href="#Dependencies" class="headerlink" title="Dependencies"></a>Dependencies</h2><ul>
<li>现在又支持共享的c-ares builds了。<ul>
<li>Refs: <a href="https://github.com/nodejs/node/commit/2253be95d0" target="_blank" rel="noopener"><code>2253be95d0</code></a>, <a href="https://github.com/nodejs/node/pull/5775" target="_blank" rel="noopener">#5775</a></li>
</ul>
</li>
<li>升级V8至5.0.71.32 + 浮动补丁。<ul>
<li>Refs: <a href="https://github.com/nodejs/node/commits/master/deps/v8" target="_blank" rel="noopener">deps/v8</a></li>
</ul>
</li>
</ul>
]]></content>
<categories>
<category>NodeJS</category>
</categories>
<tags>
<tag>nodejs</tag>
</tags>
</entry>
<entry>
<title>a tool save installed modules but forgot save to npm package.json</title>
<url>/2016/03/18/a-tool-save-installed-module-to-npm-package/</url>
<content><![CDATA[<h2 id="pkg-save"><a href="#pkg-save" class="headerlink" title="pkg-save"></a>pkg-save</h2><p><a href="https://github.com/SinalVee/pkg-save" target="_blank" rel="noopener">GitHub Repository</a></p>
<p>Save installed package(s) to package.json.</p>
<p>Sometimes, I install a npm package but forgot to add <code>--save</code> or <code>--save-dev</code>. What should I do if I want to save this package to <code>package.json</code>?</p>
<p>I try to google it but no answer found. So, I write <code>pkg-save</code> to do it.</p>
<a id="more"></a>
<h3 id="Install"><a href="#Install" class="headerlink" title="Install"></a>Install</h3><p><code>npm install pkg-save -g</code></p>
<h3 id="Usage"><a href="#Usage" class="headerlink" title="Usage"></a>Usage</h3><p><code>pkg-save <name> [option]</code></p>
<h4 id="Options"><a href="#Options" class="headerlink" title="Options"></a>Options</h4><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">-d, --dev Save package to devDependencies</span><br><span class="line">-h, --help Show help</span><br><span class="line">-v, --version Show version number</span><br></pre></td></tr></table></figure>
<h4 id="Examples"><a href="#Examples" class="headerlink" title="Examples"></a>Examples</h4><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">pkg-save lodash Save lodash to dependencies</span><br><span class="line">pkg-save lodash --dev Save lodash to devDependencies</span><br><span class="line">pkg-save lodash mocha Save lodash and mocha to dependencies</span><br><span class="line">pkg-save lodash mocha --dev Save lodash and mocha to devDependencies</span><br></pre></td></tr></table></figure>
<h3 id="License"><a href="#License" class="headerlink" title="License"></a>License</h3><p>MIT</p>
]]></content>
<categories>
<category>NodeJS</category>
</categories>
<tags>
<tag>nodejs</tag>
<tag>npm</tag>
</tags>
</entry>
<entry>
<title>ES6 + Express + Babel + Gulp + React + Webpack</title>
<url>/2016/02/24/es6-express-babel-gulp-react-webpack/</url>
<content><![CDATA[<p>自己动手才发现原来写篇好文章真的是太难了,如果评个等级的话,这篇文章大概是渣渣水平,哈哈。<br>不过,总算是写完了,也算是最近学习的一个总结吧 :)</p>
<h2 id="本文目录"><a href="#本文目录" class="headerlink" title="本文目录"></a>本文目录</h2><ul>
<li><a href="#prepare">准备工作</a></li>
<li><a href="#toc">项目目录结构</a></li>
<li><a href="#express">Express</a><ul>
<li><a href="#express-install">安装</a></li>
<li><a href="#express-server">写个server测试一下</a></li>
</ul>
</li>
<li><a href="#babel">Babel</a><ul>
<li><a href="#babel-install">安装</a></li>
<li><a href="#babelrc">配置.babelrc</a></li>
<li><a href="#babel-es6">使用es6语法编写代码</a></li>
<li><a href="#babel-transform">使用bebel转换</a></li>
</ul>
</li>
<li><a href="#gulp">Gulp</a><ul>
<li><a href="#gulp-install">安装</a></li>
<li><a href="#gulpfile">编写gulpfile</a><ul>
<li><a href="#gulpfile-default">一个简单的gulpfile</a></li>
<li><a href="#gulpfile-watch">能够监听文件更改的gulpfile</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#react-webpack">React + Webpack</a><ul>
<li><a href="#react-webpack-install">安装</a></li>
<li><a href="#webpack-config">编写webpack.config.js</a></li>
<li><a href="#gulp-webpack">在gulp中使用webpack</a></li>
<li><a href="#react">使用React</a></li>
</ul>
</li>
<li><a href="#summary">总结</a></li>
</ul>
<a id="more"></a>
<p><a id="prepare"></a></p>
<h2 id="准备工作"><a href="#准备工作" class="headerlink" title="准备工作"></a>准备工作</h2><p>作为一个noder,开始一切之前当然少不了<code>npm init</code><br>关于express, babel, gulp, webpack, react本文不进行介绍,如有需要可以到其主页自行了解。<br><a href="http://expressjs.com/" target="_blank" rel="noopener">Express</a><br><a href="https://babeljs.io/" target="_blank" rel="noopener">Babel</a><br><a href="http://gulpjs.com/" target="_blank" rel="noopener">Gulp</a><br><a href="https://facebook.github.io/react/" target="_blank" rel="noopener">React</a><br><a href="https://webpack.github.io/" target="_blank" rel="noopener">Webpack</a></p>
<p><a id="toc"></a></p>
<h2 id="项目目录结构"><a href="#项目目录结构" class="headerlink" title="项目目录结构"></a>项目目录结构</h2><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">app</span><br><span class="line">├─ lib/</span><br><span class="line">├─ public/</span><br><span class="line">│ ├─ dist/</span><br><span class="line">│ └─ src/</span><br><span class="line">│ └─ index.js</span><br><span class="line">├─ src/</span><br><span class="line">│ └─ app.js</span><br><span class="line">├─ .babelrc</span><br><span class="line">├─ index.html</span><br><span class="line">├─ gulpfile.babel.js</span><br><span class="line">├─ package.json</span><br><span class="line">├─ README.md</span><br><span class="line">└─ webpack.config.js</span><br></pre></td></tr></table></figure>
<p><a id="express"></a></p>
<h2 id="Express"><a href="#Express" class="headerlink" title="Express"></a>Express</h2><p><a id="express-install"></a></p>
<h3 id="安装"><a href="#安装" class="headerlink" title="安装"></a>安装</h3><p>这次准备纯手写,所以不用<code>express-generator</code>生成了,简单的示例尽量不使用多余的中间件。<br><code>npm install --save express body-parser</code></p>
<p><a id="express-server"></a></p>
<h3 id="写个server测试一下"><a href="#写个server测试一下" class="headerlink" title="写个server测试一下"></a>写个server测试一下</h3><figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="comment">// src/app.js</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> express = <span class="built_in">require</span>(<span class="string">'express'</span>);</span><br><span class="line"><span class="keyword">var</span> bodyParser = <span class="built_in">require</span>(<span class="string">'body-parser'</span>);</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> app = express();</span><br><span class="line"><span class="keyword">var</span> router = express.Router();</span><br><span class="line"></span><br><span class="line">app.use(bodyParser.json());</span><br><span class="line">app.use(bodyParser.urlencoded({ <span class="attr">extended</span>: <span class="literal">true</span> }));</span><br><span class="line">app.use(cookieParser());</span><br><span class="line"></span><br><span class="line">router.get(<span class="string">'/'</span>, <span class="function"><span class="keyword">function</span>(<span class="params">req, res, next</span>) </span>{</span><br><span class="line"> res.end(<span class="string">'Hello World!'</span>);</span><br><span class="line">});</span><br><span class="line"></span><br><span class="line">app.use(<span class="string">'/'</span>, router);</span><br><span class="line"></span><br><span class="line">app.listen(<span class="number">3000</span>, <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>{</span><br><span class="line"> <span class="built_in">console</span>.log(<span class="string">'server listening at port 3000...'</span>);</span><br><span class="line">});</span><br></pre></td></tr></table></figure>
<p>简单起见,404和error handler就不写了。<br><code>node src/app.js</code>跑起来,浏览器打开<a href="http://localhost:3000" target="_blank" rel="noopener">http://localhost:3000</a>,可以看到页面中显示<code>Hello World!</code>了。</p>
<p><a id="babel"></a></p>
<h2 id="Babel"><a href="#Babel" class="headerlink" title="Babel"></a>Babel</h2><p>babel升级到6.x之后,需要明确指定转换,我们使用预设的es2015。</p>
<p><a id="babel-install"></a></p>
<h3 id="安装-1"><a href="#安装-1" class="headerlink" title="安装"></a>安装</h3><p><code>npm install -g babel-core</code><br><code>npm install --save-dev babel-core babel-preset-es2015</code></p>
<p><a id="babelrc"></a></p>
<h3 id="配置-babelrc"><a href="#配置-babelrc" class="headerlink" title="配置.babelrc"></a>配置.babelrc</h3><p>在根目录新建.babelrc文件,配置如下:</p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">{</span><br><span class="line"> "presets": ["es2015"]</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<p><a id="babel-es6"></a></p>
<h3 id="使用es6语法编写代码"><a href="#使用es6语法编写代码" class="headerlink" title="使用es6语法编写代码"></a>使用es6语法编写代码</h3><p>我们现在将之前写过的<code>src/app.js</code>修改为es6语法</p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">// src/app.js</span><br><span class="line"></span><br><span class="line">import express, { Router } from 'express';</span><br><span class="line">import bodyParser from 'body-parser';</span><br><span class="line"></span><br><span class="line">let app = express();</span><br><span class="line">let router = Router();</span><br><span class="line"></span><br><span class="line">app.use(bodyParser.json());</span><br><span class="line">app.use(bodyParser.urlencoded({ extended: true }));</span><br><span class="line">app.use(cookieParser());</span><br><span class="line"></span><br><span class="line">router.get('/', (req, res, next) => {</span><br><span class="line"> res.end('Hello World!');</span><br><span class="line">});</span><br><span class="line">app.use('/', router);</span><br><span class="line"></span><br><span class="line">app.listen(3000, () => {</span><br><span class="line"> console.log('server listening at port 3000...');</span><br><span class="line">});</span><br></pre></td></tr></table></figure>
<p><a id="babel-transform"></a></p>
<h3 id="使用bebel转换"><a href="#使用bebel转换" class="headerlink" title="使用bebel转换"></a>使用bebel转换</h3><p>将代码修改为es6语法之后,就可以使用babel进行转换了。<br>使用命令<code>babel src -d lib</code><br>可以看到控制台中显示:</p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">src/app.js -> lib/app.js</span><br></pre></td></tr></table></figure>
<p>之后还是运行一下看看效果,浏览器打开<a href="http://localhost:3000" target="_blank" rel="noopener">http://localhost:3000</a>,我们和熟悉的<code>Hello World</code>又见面啦。</p>
<p><a id="gulp"></a></p>
<h2 id="Gulp"><a href="#Gulp" class="headerlink" title="Gulp"></a>Gulp</h2><p>每次修改完代码都要重新用babel转换一次是不是很麻烦?别怕,我们有gulp。</p>
<p><a id="gulp-install"></a></p>
<h3 id="安装-2"><a href="#安装-2" class="headerlink" title="安装"></a>安装</h3><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">npm install -g gulp-cli</span><br><span class="line">npm install --save-dev gulp gulp-babel</span><br></pre></td></tr></table></figure>
<p><a id="gulpfile"></a></p>
<h3 id="编写gulpfile"><a href="#编写gulpfile" class="headerlink" title="编写gulpfile"></a>编写gulpfile</h3><p>在根目录新建一个gulpfile.babel.js文件。<br>gulp原生并不支持es6语法,但是我们可以告诉gulp使用babel将gulpfile转换为es5,方法就是将gulpfile命名为gulpfile.babel.js</p>
<p><a id="gulpfile-default"></a></p>
<h4 id="一个简单的gulpfile"><a href="#一个简单的gulpfile" class="headerlink" title="一个简单的gulpfile"></a>一个简单的gulpfile</h4><p>我们先写一个简单的gulpfile测试一下gulp是否能够正常工作。</p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">import gulp from 'gulp';</span><br><span class="line">import babel from 'gulp-babel';</span><br><span class="line"></span><br><span class="line">gulp.task('default', () => {</span><br><span class="line"> return gulp.src('src/**/*.js')</span><br><span class="line"> .pipe(babel())</span><br><span class="line"> .pipe(gulp.dest('lib'));</span><br><span class="line">});</span><br></pre></td></tr></table></figure>
<p>控制台执行<code>gulp</code>,可以看到:</p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">[13:00:35] Requiring external module babel-register</span><br><span class="line">[13:00:36] Using gulpfile /path/to/file/gulpfile.babel.js</span><br><span class="line">[13:00:36] Starting 'default'...</span><br><span class="line">[13:00:36] Finished 'default' after 191 ms</span><br></pre></td></tr></table></figure>
<p>然后lib文件夹下就生成了转换后的文件了。</p>
<p><a id="gulpfile-watch"></a></p>
<h4 id="能够监听文件更改的gulpfile"><a href="#能够监听文件更改的gulpfile" class="headerlink" title="能够监听文件更改的gulpfile"></a>能够监听文件更改的gulpfile</h4><p>虽然上面的gulpfile能够将使用了,但是还是跟之前直接用babel一样,每次都要gulp一下,下面我们就来写一个能够监听文件的gulpfile。当文件被修改之后,自动将文件转换。<br>这里使用<code>gulp-watch</code>监听文件更改。<br><code>npm install --save-dev gulp-watch</code></p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">import gulp from 'gulp';</span><br><span class="line">import watch from 'gulp-watch';</span><br><span class="line">import babel from 'gulp-babel';</span><br><span class="line"></span><br><span class="line">gulp.task('transform', () => {</span><br><span class="line"> return gulp.src('src/**/*.js')</span><br><span class="line"> .pipe(babel())</span><br><span class="line"> .pipe(gulp.dest('lib'));</span><br><span class="line">});</span><br><span class="line"></span><br><span class="line">gulp.task('watch', () => {</span><br><span class="line"> return gulp.src('src/**/*.js')</span><br><span class="line"> .pipe(watch('src/**/*.js', {</span><br><span class="line"> verbose: true</span><br><span class="line"> }))</span><br><span class="line"> .pipe(babel())</span><br><span class="line"> .pipe(gulp.dest('lib'));</span><br><span class="line">});</span><br><span class="line"></span><br><span class="line">gulp.task('default', () => {</span><br><span class="line"> gulp.start('transform');</span><br><span class="line">});</span><br></pre></td></tr></table></figure>
<p>控制台执行<code>gulp watch</code></p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">[14:11:46] Requiring external module babel-register</span><br><span class="line">[14:11:47] Using gulpfile /file/to/path/gulpfile.babel.js</span><br><span class="line">[14:11:47] Starting 'watch'...</span><br></pre></td></tr></table></figure>
<p>然后修改app.js并保存,可以看到控制台中多了一行信息</p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">[14:13:20] app.js was changed</span><br></pre></td></tr></table></figure>
<p>对于gulp其他的用法这里就不细说了,有兴趣的可以去看桑大<code>i5ting</code>的<a href="http://i5ting.github.io/stuq-gulp/" target="_blank" rel="noopener">Gulp实战和原理解析(以weui作为项目实例)</a></p>
<p><a id="react-webpack"></a></p>
<h2 id="React-Webpack"><a href="#React-Webpack" class="headerlink" title="React + Webpack"></a>React + Webpack</h2><p><a id="react-webpack-install"></a></p>
<h3 id="安装-3"><a href="#安装-3" class="headerlink" title="安装"></a>安装</h3><p>react<br><code>npm install --save react react-dom</code><br>webpack<br><code>npm install --save-dev webpack webpack-dev-server</code><br>为了编译jsx,我们还需要其他一些模块<br><code>npm install --save-dev babel-loader babel-preset-react</code></p>
<p><a id="webpack-config"></a></p>
<h3 id="编写webpack-config-js"><a href="#编写webpack-config-js" class="headerlink" title="编写webpack.config.js"></a>编写webpack.config.js</h3><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">var path = require('path');</span><br><span class="line">var webpack = require('webpack');</span><br><span class="line"></span><br><span class="line">module.exports = {</span><br><span class="line"> devtool: 'eval',</span><br><span class="line"> entry: {</span><br><span class="line"> public: './public/src/index'</span><br><span class="line"> },</span><br><span class="line"> output: {</span><br><span class="line"> path: path.join(__dirname, 'public/dist'),</span><br><span class="line"> filename: 'bundle.js',</span><br><span class="line"> publicPath: 'public/dist'</span><br><span class="line"> },</span><br><span class="line"> plugins: [],</span><br><span class="line"> module: {</span><br><span class="line"> loaders: [</span><br><span class="line"> {</span><br><span class="line"> test: /\.js$/,</span><br><span class="line"> include: [path.join(__dirname, 'public/src')],</span><br><span class="line"> loader: 'babel',</span><br><span class="line"> query: {</span><br><span class="line"> presets: ['react', 'es2015']</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> ]</span><br><span class="line"> }</span><br><span class="line">};</span><br></pre></td></tr></table></figure>
<p><a id="gulp-webpack"></a></p>
<h3 id="在gulp中使用webpack"><a href="#在gulp中使用webpack" class="headerlink" title="在gulp中使用webpack"></a>在gulp中使用webpack</h3><p>修改<code>gulpfile.babel.js</code>,添加<code>build</code>和<code>webpack-dev-server</code>任务,分别是生成打包文件和启动开发服务器,并将<code>default</code>修改为同时执行<code>transform</code>和<code>webpack-dev-server</code>。</p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">import gulp from 'gulp';</span><br><span class="line">import gutil from 'gulp-util';</span><br><span class="line">import watch from 'gulp-watch';</span><br><span class="line">import babel from 'gulp-babel';</span><br><span class="line">import webpack from 'webpack';</span><br><span class="line">import WebpackDevServer from 'webpack-dev-server';</span><br><span class="line"></span><br><span class="line">import webpackConfig from './webpack.config.js';</span><br><span class="line"></span><br><span class="line">// transform</span><br><span class="line">gulp.task('transform', () => {</span><br><span class="line"> return gulp.src('src/**/*.js')</span><br><span class="line"> .pipe(babel())</span><br><span class="line"> .pipe(gulp.dest('lib'));</span><br><span class="line">});</span><br><span class="line"></span><br><span class="line">// watch transform</span><br><span class="line">gulp.task('watch-transform', () => {</span><br><span class="line"> return gulp.src('src/**/*.js')</span><br><span class="line"> .pipe(watch('src/**/*.js', {</span><br><span class="line"> verbose: true</span><br><span class="line"> }))</span><br><span class="line"> .pipe(babel())</span><br><span class="line"> .pipe(gulp.dest('lib'));</span><br><span class="line">});</span><br><span class="line"></span><br><span class="line">gulp.task('webpack:build', (callback) => {</span><br><span class="line"> // modify some webpack config options</span><br><span class="line"> var myConfig = Object.create(webpackConfig);</span><br><span class="line"> myConfig.plugins = myConfig.plugins.concat(</span><br><span class="line"> new webpack.DefinePlugin({</span><br><span class="line"> 'process.env': {</span><br><span class="line"> // This has effect on the react lib size</span><br><span class="line"> 'NODE_ENV': JSON.stringify('production')</span><br><span class="line"> }</span><br><span class="line"> }),</span><br><span class="line"> new webpack.optimize.DedupePlugin(),</span><br><span class="line"> new webpack.optimize.UglifyJsPlugin()</span><br><span class="line"> );</span><br><span class="line"></span><br><span class="line"> // run webpack</span><br><span class="line"> webpack(myConfig, (err, stats) => {</span><br><span class="line"> if (err)</span><br><span class="line"> throw new gutil.PluginError('webpack:build', err);</span><br><span class="line"> gutil.log('[webpack:build]', stats.toString({</span><br><span class="line"> colors: true</span><br><span class="line"> }));</span><br><span class="line"> callback();</span><br><span class="line"> });</span><br><span class="line">});</span><br><span class="line"></span><br><span class="line">gulp.task('webpack-dev-server', (callback) => {</span><br><span class="line"> // modify some webpack config options</span><br><span class="line"> var myConfig = Object.create(webpackConfig);</span><br><span class="line"> myConfig.devtool = 'eval';</span><br><span class="line"> myConfig.debug = true;</span><br><span class="line"></span><br><span class="line"> // Start a webpack-dev-server</span><br><span class="line"> new WebpackDevServer(webpack(myConfig), {</span><br><span class="line"> publicPath: '/' + myConfig.output.publicPath,</span><br><span class="line"> stats: {</span><br><span class="line"> colors: true</span><br><span class="line"> }</span><br><span class="line"> }).listen(3001, 'localhost', (err) => {</span><br><span class="line"> if (err) throw new gutil.PluginError('webpack-dev-server', err);</span><br><span class="line"> gutil.log('[webpack-dev-server]', 'http://localhost:3001/');</span><br><span class="line"> });</span><br><span class="line">});</span><br><span class="line"></span><br><span class="line">gulp.task('default', ['watch-transform', 'webpack-dev-server']);</span><br></pre></td></tr></table></figure>
<p><a id="react"></a></p>
<h3 id="使用React"><a href="#使用React" class="headerlink" title="使用React"></a>使用React</h3><p>在根目录下创建<code>index.html</code>文件</p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line"><!DOCTYPE html></span><br><span class="line"><html></span><br><span class="line"> <head></span><br><span class="line"> <meta charset="UTF-8" /></span><br><span class="line"> <title>Hello Wrold</title></span><br><span class="line"> </head></span><br><span class="line"> <body></span><br><span class="line"> <div id="root"></div></span><br><span class="line"> <script src="http://127.0.0.1:3001/public/dist/bundle.js"></script></span><br><span class="line"> </body></span><br><span class="line"></html></span><br></pre></td></tr></table></figure>
<p>之后在<code>public/src</code>目录创建<code>index.js</code>文件,简单的写个hello world.</p>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="keyword">import</span> React, { Component } <span class="keyword">from</span> <span class="string">'react'</span>;</span><br><span class="line"><span class="keyword">import</span> ReactDOM <span class="keyword">from</span> <span class="string">'react-dom'</span>;</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">App</span> <span class="keyword">extends</span> <span class="title">Component</span> </span>{</span><br><span class="line"> render() {</span><br><span class="line"> <span class="keyword">return</span> (</span><br><span class="line"> <h1>Hello Wrold!!<span class="xml"><span class="tag"></<span class="name">h1</span>></span></span></span><br><span class="line"> );</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">ReactDOM.render(</span><br><span class="line"> <App />,</span><br><span class="line"> <span class="built_in">document</span>.getElementById(<span class="string">'root'</span>)</span><br><span class="line">);</span><br></pre></td></tr></table></figure>
<p>控制台执行<code>gulp webpack-dev-server</code>,打开<a href="http://localhost:3001/" target="_blank" rel="noopener">http://localhost:3001</a><br>我们和<code>Hello world!</code>第三次见面了~</p>
<p><a id="summary"></a></p>
<h2 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h2><p>到这里文章就结束了,然而这只是文章的结束,现在只是把大体的结构搭建起来了,剩下要做的还有很多,继续加油把~<br>PS: 我也不知道这种目录结构是否合理,如有不同意见,欢迎拍砖~</p>
]]></content>
<categories>
<category>NodeJS</category>
</categories>
<tags>
<tag>nodejs</tag>
<tag>es2015</tag>
<tag>express</tag>
<tag>babel</tag>
<tag>gulp</tag>
</tags>
</entry>
<entry>
<title>nodejs articles collection</title>
<url>/2016/02/20/nodejs-articles/</url>
<content><![CDATA[<p><img src="/images/nodejs.png" alt=""><br><strong>This post is used to collect articles about <code>nodejs</code>.</strong></p>
<h1 id="Table-of-Contents"><a href="#Table-of-Contents" class="headerlink" title="Table of Contents"></a>Table of Contents</h1><ul>
<li><a href="#es2015">ES2015</a></li>
<li><a href="#javascript">JavaScript</a></li>
<li><a href="#koa">Koa</a></li>
<li><a href="#promise">Promise</a></li>
</ul>
<p><a id="es2015"></a></p>
<h2 id="ES2015"><a href="#ES2015" class="headerlink" title="ES2015"></a>ES2015</h2><p><a href="http://es6.ruanyifeng.com/" target="_blank" rel="noopener">ECMAScript 6入门</a><br><a href="http://gank.io/post/564151c1f1df1210001c9161" target="_blank" rel="noopener">给 JavaScript 初心者的 ES2015 实战</a></p>
<p><a id="javascript"></a></p>
<h2 id="JavaScript"><a href="#JavaScript" class="headerlink" title="JavaScript"></a>JavaScript</h2><p><a href="https://github.com/loverajoel/jstips" target="_blank" rel="noopener">jstips</a> — One JS tip every day!<br><a href="https://cnodejs.org/topic/56a050ac8392272262331d62" target="_blank" rel="noopener">每天一条JS小知识</a> — jstips Chinese translation</p>
<p><a id="koa"></a></p>
<h2 id="Koa"><a href="#Koa" class="headerlink" title="Koa"></a>Koa</h2><p><a href="http://base-n.github.io/koa-generator-examples/" target="_blank" rel="noopener">一起学koa</a> — a koa examples book</p>
<p><a id="promise"></a></p>
<h2 id="Promise"><a href="#Promise" class="headerlink" title="Promise"></a>Promise</h2><p><a href="http://pouchdb.com/2015/05/18/we-have-a-problem-with-promises.html" target="_blank" rel="noopener">We have a problem with promises</a></p>
]]></content>
<categories>
<category>NodeJS</category>
</categories>
<tags>
<tag>nodejs</tag>
</tags>
</entry>
<entry>
<title>mongodb备份及恢复</title>
<url>/2015/11/11/mongodb-backup-and-restore/</url>
<content><![CDATA[<h2 id="备份"><a href="#备份" class="headerlink" title="备份"></a>备份</h2><p><code>mongodump --host 127.0.0.1 --port 27017 -d {database} --out {out-path}</code></p>
<h2 id="恢复"><a href="#恢复" class="headerlink" title="恢复"></a>恢复</h2><p><code>mongorestore -d {database} --drop {src-path}</code></p>
]]></content>
<categories>
<category>Database</category>
<category>MongoDB</category>
</categories>
<tags>
<tag>mongodb</tag>
</tags>
</entry>
<entry>
<title>使用n更新nodejs</title>
<url>/2015/11/06/update-node-with-n/</url>
<content><![CDATA[<p>node有一个模块叫n,是专门用来管理node.js的版本的。</p>
<p>第一步:<br>安装n模块<br><code>npm install -g n</code></p>
<p>第二步:<br>升级node.js到最新稳定版<br><code>n stable</code></p>
<p>n后面也可以跟随版本号比如:</p>
<p><code>n v0.10.26</code> 或 <code>n 0.10.26</code></p>
]]></content>
<categories>
<category>NodeJS</category>
</categories>
<tags>
<tag>nodejs</tag>
</tags>
</entry>
<entry>
<title>Linux用户相关操作</title>
<url>/2015/11/06/linux-user-commands/</url>
<content><![CDATA[<h2 id="添加用户"><a href="#添加用户" class="headerlink" title="添加用户"></a>添加用户</h2><p><code>useradd 选项 用户名</code></p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">-c comment 指定一段注释性描述。</span><br><span class="line">-d 目录 指定用户主目录,如果此目录不存在,则同时使用-m选项,可以创建主目录。</span><br><span class="line">-g 用户组 指定用户所属的用户组。</span><br><span class="line">-G 用户组,用户组 指定用户所属的附加组。</span><br><span class="line">-s Shell文件 指定用户的登录Shell。</span><br><span class="line">-u 用户号 指定用户的用户号,如果同时有-o选项,则可以重复使用其他用户的标识号。</span><br></pre></td></tr></table></figure>
<h2 id="删除用户"><a href="#删除用户" class="headerlink" title="删除用户"></a>删除用户</h2><p><code>userdel 选项 用户名</code></p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">-f, --force force removal of files, even if not owned by user</span><br><span class="line">-h, --help display this help message and exit</span><br><span class="line">-r, --remove remove home directory and mail spool</span><br></pre></td></tr></table></figure>
<h2 id="修改用户"><a href="#修改用户" class="headerlink" title="修改用户"></a>修改用户</h2><p><code>usermod 选项 用户名</code><br>选项与useradd基本一致 </p>
<h2 id="用户密码管理"><a href="#用户密码管理" class="headerlink" title="用户密码管理"></a>用户密码管理</h2><p><code>passwd 选项 用户名</code></p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">-l 锁定密码,即禁用账号。</span><br><span class="line">-u 密码解锁。</span><br><span class="line">-d 使账号无密码。</span><br><span class="line">-f 强迫用户下次登录时修改密码。</span><br><span class="line">如果不使用用户名,则修改当前用户的密码</span><br></pre></td></tr></table></figure>
]]></content>
<categories>
<category>Linux</category>
</categories>
<tags>
<tag>linux</tag>
</tags>
</entry>
<entry>
<title>git添加多个远程url</title>
<url>/2015/11/06/add-origin-urls-to-git-repo/</url>
<content><![CDATA[<p>假设要添加的三个url为</p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line"><url1>: https://github.com/sinalvee/111.git</span><br><span class="line"><url2>: https://github.com/sinalvee/222.git</span><br><span class="line"><url3>: https://github.com/sinalvee/222.git</span><br></pre></td></tr></table></figure>
<p>使用如下方法</p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">git remote add origin <url1></span><br><span class="line">git remote set-url --add origin <url2></span><br><span class="line">git remote set-url --add origin <url3></span><br></pre></td></tr></table></figure>
<p>push的时候直接<code>git push origin master</code>即可依次向三个地址提交</p>
]]></content>
<categories>
<category>Git</category>
</categories>
<tags>
<tag>git</tag>
</tags>
</entry>
<entry>
<title>Sails+wechat(解决sails无法处理微信消息)</title>
<url>/2015/09/18/sails-wechat/</url>
<content><![CDATA[<p><a href="https://github.com/balderdashy/sails" target="_blank" rel="noopener">sails</a>框架使用<a href="https://github.com/node-webot/wechat" target="_blank" rel="noopener">wechat</a> 的时候能够通过验证却不能处理微信消息,原因是sails默认的bodyPaser(<a href="https://github.com/balderdashy/skipper" target="_blank" rel="noopener">skipper</a>)不支持’text/xml’形式的请求(<a href="https://github.com/balderdashy/sails/issues/2714" target="_blank" rel="noopener">sails issues#2714</a>)</p>
<p>YunnuY同学使用<a href="https://www.npmjs.com/package/express-xml-bodyparser" target="_blank" rel="noopener">express-xml-bodyparser</a>和<a href="https://www.npmjs.com/package/body-parser" target="_blank" rel="noopener">body-parser</a>覆盖了sails默认的bodyParser</p>
<p><a href="https://github.com/YunnuY/sweat/blob/master/config/http.js" target="_blank" rel="noopener">https://github.com/YunnuY/sweat/blob/master/config/http.js</a></p>
<p>由于body-paser后来更新,所以这里的代码要稍微修改一下,将<code>var bodyParser = require('body-parser')();</code>修改为<code>var bodyParser = require('body-parser')().json();</code></p>
<hr>
<p>但是公司的项目中还有包含文件的请求,此时body-paser就不能满足需求了,因此还是要重新使用sails默认的skipper,代码如下:</p>
<pre><code>bodyParser: function() {
var xmlParser = require('express-xml-bodyparser')();
var skipper = require('skipper')();
return function(req, res, next) {
if (req.headers &amp;&amp; (req.headers['content-type'] == 'text/xml' || req.headers['content-type'] == 'application/xml')) {
return xmlParser(req, res, next);
}
return skipper(req, res, next);
};
}</code></pre><p>目前程序能够正常处理微信消息和常规请求,如果出现问题我会及时更新。</p>
]]></content>
<categories>
<category>NodeJS</category>
</categories>
<tags>
<tag>nodejs</tag>
<tag>sails</tag>
<tag>wechat</tag>
</tags>
</entry>
<entry>
<title>Java实现二叉查找树转为排序的双向链表</title>
<url>/2015/06/13/binary-search-tree-to-sorted-doubly-linked-list-in-java/</url>
<content><![CDATA[<p>1.把二元查找树转变成排序的双向链表<br>题目:<br>输入一棵二元查找树,将该二元查找树转换成一个排序的双向链表。<br>要求不能创建任何新的结点,只调整指针的指向。</p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line"> 10</span><br><span class="line"> / \</span><br><span class="line"> 6 14</span><br><span class="line"> / \ / \</span><br><span class="line">4 8 12 16</span><br></pre></td></tr></table></figure>
<p>转换成双向链表<br>4=6=8=10=12=14=16。<br>首先我们定义的二元查找树节点的数据结构如下:<br>struct BSTreeNode<br>{<br>int m_nValue; // value of node<br>BSTreeNode *m_pLeft; // left child of node<br>BSTreeNode *m_pRight; // right child of node<br>};</p>
<pre class="lang:java decode:true ">
class BSTreeToDoubleLinkNode {
//二叉树类
class BSTreeNode {
Integer m_value;
BSTreeNode m_left;
BSTreeNode m_right;
//二叉树添加新节点
public void addNewBSTreeNode(int value) {
if (m_value == null) {
m_value = value;
} else if (m_value > value) {
if (m_left == null) {
m_left = new BSTreeNode();
m_left.addNewBSTreeNode(value);
} else {
m_left.addNewBSTreeNode(value);
}
} else if (m_value < value) {
if (m_right == null) {
m_right = new BSTreeNode();
m_right.addNewBSTreeNode(value);
} else {
m_right.addNewBSTreeNode(value);
}
} else {
System.out.println("repeat node.");
}
}
}
//双向链表索引
BSTreeNode pIndex = null;
BSTreeNode pHead = null;
//中序遍历二叉树
public void inOrderTraversal(BSTreeNode pNode) {
if (pNode == null) {
System.out.println("pNode is null.");
return;
} else {
if (pNode.m_left != null) {
inOrderTraversal(pNode.m_left);
}
//转换当前节点为链表
convertToDoubleLinkNode(pNode);
if (pNode.m_right != null) {
inOrderTraversal(pNode.m_right);
}
}
}
//转换当前节点为链表
public void convertToDoubleLinkNode(BSTreeNode pNode) {
pNode.m_left = pIndex;
if (null == pIndex) {
pHead = pNode;
} else {
pIndex.m_right = pNode;
}
pIndex = pNode;
System.out.print(pNode.m_value + " ");
}
public static void main(String[] args) {
BSTreeToDoubleLinkNode b = new BSTreeToDoubleLinkNode();
BSTreeNode pNode = b.new BSTreeNode();
pNode.addNewBSTreeNode(10);
pNode.addNewBSTreeNode(6);
pNode.addNewBSTreeNode(14);
pNode.addNewBSTreeNode(4);
pNode.addNewBSTreeNode(8);
pNode.addNewBSTreeNode(12);
pNode.addNewBSTreeNode(16);
b.inOrderTraversal(pNode);
}
}
</pre>
]]></content>
<categories>
<category>Algorithm</category>
<category>Data Structure</category>
</categories>
<tags>
<tag>java</tag>
</tags>
</entry>
<entry>
<title>配置gvim使之不自动生成备份文件的方法</title>
<url>/2015/03/26/gvim-nobackup/</url>
<content><![CDATA[<p>默认情况下使用gvim,在保存文件时会自动产生带~号的备份文件,强迫症选手真是受不了,现给出解决方案:</p>
<p>1.打开gvim,选择菜单栏的编辑-启动设定<br>2.在“behave mswin”下方添加一行 set nobackup<br>3.:wq 退出并保存</p>
<p>以上,解决。</p>
]]></content>
<categories>
<category>Notes</category>
</categories>
</entry>
<entry>
<title>c3p0配置信息</title>
<url>/2014/12/31/c3p0-config/</url>
<content><![CDATA[<p>c3p0是一个开源的JDBC连接池,它实现了数据源和JNDI绑定,支持JDBC3规范和JDBC2的标准扩展。目前使用它的开源项目有Hibernate,Spring等。</p>
<figure class="highlight xml"><table><tr><td class="code"><pre><span class="line"><span class="tag"><<span class="name">c3p0-config</span>></span></span><br><span class="line"><span class="tag"><<span class="name">default-config</span>></span></span><br><span class="line"></span><br><span class="line"><span class="comment"><!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 --></span></span><br><span class="line"><span class="tag"><<span class="name">property</span> <span class="attr">name</span>=<span class="string">"acquireIncrement"</span>></span>3<span class="tag"></<span class="name">property</span>></span></span><br><span class="line"></span><br><span class="line"><span class="comment"><!--定义在从数据库获取新连接失败后重复尝试的次数。Default: 30 --></span></span><br><span class="line"><span class="tag"><<span class="name">property</span> <span class="attr">name</span>=<span class="string">"acquireRetryAttempts"</span>></span>30<span class="tag"></<span class="name">property</span>></span></span><br><span class="line"></span><br><span class="line"><span class="comment"><!--两次连接中间隔时间,单位毫秒。Default: 1000 --></span></span><br><span class="line"><span class="tag"><<span class="name">property</span> <span class="attr">name</span>=<span class="string">"acquireRetryDelay"</span>></span>1000<span class="tag"></<span class="name">property</span>></span></span><br><span class="line"></span><br><span class="line"><span class="comment"><!--连接关闭时默认将所有未提交的操作回滚。Default: false --></span></span><br><span class="line"><span class="tag"><<span class="name">property</span> <span class="attr">name</span>=<span class="string">"autoCommitOnClose"</span>></span>false<span class="tag"></<span class="name">property</span>></span></span><br><span class="line"></span><br><span class="line"><span class="comment"><!--c3p0将建一张名为Test的空表,并使用其自带的查询语句进行测试。如果定义了这个参数那么属性preferredTestQuery将被忽略。你不能在这张Test表上进行任何操作,它将只供c3p0测试使用。Default: null--></span></span><br><span class="line"><span class="tag"><<span class="name">property</span> <span class="attr">name</span>=<span class="string">"automaticTestTable"</span>></span>Test<span class="tag"></<span class="name">property</span>></span></span><br><span class="line"></span><br><span class="line"><span class="comment"><!--获取连接失败将会引起所有等待连接池来获取连接的线程抛出异常。但是数据源仍有效保留,并在下次调用getConnection()的时候继续尝试获取连接。如果设为true,那么在尝试获取连接失败后该数据源将申明已断开并永久关闭。Default: false--></span></span><br><span class="line"><span class="tag"><<span class="name">property</span> <span class="attr">name</span>=<span class="string">"breakAfterAcquireFailure"</span>></span>false<span class="tag"></<span class="name">property</span>></span></span><br><span class="line"></span><br><span class="line"><span class="comment"><!--当连接池用完时客户端调用getConnection()后等待获取新连接的时间,超时后将抛出SQLException,如设为0则无限期等待。单位毫秒。Default: 0 --></span></span><br><span class="line"><span class="tag"><<span class="name">property</span> <span class="attr">name</span>=<span class="string">"checkoutTimeout"</span>></span>100<span class="tag"></<span class="name">property</span>></span></span><br><span class="line"></span><br><span class="line"><span class="comment"><!--通过实现ConnectionTester或QueryConnectionTester的类来测试连接。类名需制定全路径。Default: com.mchange.v2.c3p0.impl.DefaultConnectionTester--></span></span><br><span class="line"><span class="tag"><<span class="name">property</span> <span class="attr">name</span>=<span class="string">"connectionTesterClassName"</span>></span><span class="tag"></<span class="name">property</span>></span></span><br><span class="line"></span><br><span class="line"><span class="comment"><!--指定c3p0 libraries的路径,如果(通常都是这样)在本地即可获得那么无需设置,默认null即可Default: null--></span></span><br><span class="line"><span class="tag"><<span class="name">property</span> <span class="attr">name</span>=<span class="string">"factoryClassLocation"</span>></span>null<span class="tag"></<span class="name">property</span>></span></span><br><span class="line"></span><br><span class="line"><span class="comment"><!--Strongly disrecommended. Setting this to true may lead to subtle and bizarre bugs.(文档原文)作者强烈建议不使用的一个属性--></span></span><br><span class="line"><span class="tag"><<span class="name">property</span> <span class="attr">name</span>=<span class="string">"forceIgnoreUnresolvedTransactions"</span>></span>false<span class="tag"></<span class="name">property</span>></span></span><br><span class="line"></span><br><span class="line"><span class="comment"><!--每60秒检查所有连接池中的空闲连接。Default: 0 --></span></span><br><span class="line"><span class="tag"><<span class="name">property</span> <span class="attr">name</span>=<span class="string">"idleConnectionTestPeriod"</span>></span>60<span class="tag"></<span class="name">property</span>></span></span><br><span class="line"></span><br><span class="line"><span class="comment"><!--初始化时获取三个连接,取值应在minPoolSize与maxPoolSize之间。Default: 3 --></span></span><br><span class="line"><span class="tag"><<span class="name">property</span> <span class="attr">name</span>=<span class="string">"initialPoolSize"</span>></span>3<span class="tag"></<span class="name">property</span>></span></span><br><span class="line"></span><br><span class="line"><span class="comment"><!--最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 --></span></span><br><span class="line"><span class="tag"><<span class="name">property</span> <span class="attr">name</span>=<span class="string">"maxIdleTime"</span>></span>60<span class="tag"></<span class="name">property</span>></span></span><br><span class="line"></span><br><span class="line"><span class="comment"><!--连接池中保留的最大连接数。Default: 15 --></span></span><br><span class="line"><span class="tag"><<span class="name">property</span> <span class="attr">name</span>=<span class="string">"maxPoolSize"</span>></span>15<span class="tag"></<span class="name">property</span>></span></span><br><span class="line"></span><br><span class="line"><span class="comment"><!--JDBC的标准参数,用以控制数据源内加载的PreparedStatements数量。但由于预缓存的statements属于单个connection而不是整个连接池。所以设置这个参数需要考虑到多方面的因素。如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default: 0--></span></span><br><span class="line"><span class="tag"><<span class="name">property</span> <span class="attr">name</span>=<span class="string">"maxStatements"</span>></span>100<span class="tag"></<span class="name">property</span>></span></span><br><span class="line"></span><br><span class="line"><span class="comment"><!--maxStatementsPerConnection定义了连接池内单个连接所拥有的最大缓存statements数。Default: 0 --></span></span><br><span class="line"><span class="tag"><<span class="name">property</span> <span class="attr">name</span>=<span class="string">"maxStatementsPerConnection"</span>></span><span class="tag"></<span class="name">property</span>></span></span><br><span class="line"></span><br><span class="line"><span class="comment"><!--c3p0是异步操作的,缓慢的JDBC操作通过帮助进程完成。扩展这些操作可以有效的提升性能通过多线程实现多个操作同时被执行。Default: 3--></span></span><br><span class="line"><span class="tag"><<span class="name">property</span> <span class="attr">name</span>=<span class="string">"numHelperThreads"</span>></span>3<span class="tag"></<span class="name">property</span>></span></span><br><span class="line"></span><br><span class="line"><span class="comment"><!--当用户调用getConnection()时使root用户成为去获取连接的用户。主要用于连接池连接非c3p0的数据源时。Default: null--></span></span><br><span class="line"><span class="tag"><<span class="name">property</span> <span class="attr">name</span>=<span class="string">"overrideDefaultUser"</span>></span>root<span class="tag"></<span class="name">property</span>></span></span><br><span class="line"></span><br><span class="line"><span class="comment"><!--与overrideDefaultUser参数对应使用的一个参数。Default: null--></span></span><br><span class="line"><span class="tag"><<span class="name">property</span> <span class="attr">name</span>=<span class="string">"overrideDefaultPassword"</span>></span>password<span class="tag"></<span class="name">property</span>></span></span><br><span class="line"></span><br><span class="line"><span class="comment"><!--密码。Default: null--></span></span><br><span class="line"><span class="tag"><<span class="name">property</span> <span class="attr">name</span>=<span class="string">"password"</span>></span><span class="tag"></<span class="name">property</span>></span></span><br><span class="line"></span><br><span class="line"><span class="comment"><!--定义所有连接测试都执行的测试语句。在使用连接测试的情况下这个一显著提高测试速度。注意:测试的表必须在初始数据源的时候就存在。Default: null--></span></span><br><span class="line"><span class="tag"><<span class="name">property</span> <span class="attr">name</span>=<span class="string">"preferredTestQuery"</span>></span>select id from test where id=1<span class="tag"></<span class="name">property</span>></span></span><br><span class="line"></span><br><span class="line"><span class="comment"><!--用户修改系统配置参数执行前最多等待300秒。Default: 300 --></span></span><br><span class="line"><span class="tag"><<span class="name">property</span> <span class="attr">name</span>=<span class="string">"propertyCycle"</span>></span>300<span class="tag"></<span class="name">property</span>></span></span><br><span class="line"></span><br><span class="line"><span class="comment"><!--因性能消耗大请只在需要的时候使用它。如果设为true那么在每个connection提交的时候都将校验其有效性。建议使用idleConnectionTestPeriod或automaticTestTable等方法来提升连接测试的性能。Default: false --></span></span><br><span class="line"><span class="tag"><<span class="name">property</span> <span class="attr">name</span>=<span class="string">"testConnectionOnCheckout"</span>></span>false<span class="tag"></<span class="name">property</span>></span></span><br><span class="line"></span><br><span class="line"><span class="comment"><!--如果设为true那么在取得连接的同时将校验连接的有效性。Default: false --></span></span><br><span class="line"><span class="tag"><<span class="name">property</span> <span class="attr">name</span>=<span class="string">"testConnectionOnCheckin"</span>></span>true<span class="tag"></<span class="name">property</span>></span></span><br><span class="line"></span><br><span class="line"><span class="comment"><!--用户名。Default: null--></span></span><br><span class="line"><span class="tag"><<span class="name">property</span> <span class="attr">name</span>=<span class="string">"user"</span>></span>root<span class="tag"></<span class="name">property</span>></span></span><br></pre></td></tr></table></figure>
<p>在Hibernate(spring管理)中的配置:</p>
<figure class="highlight xml"><table><tr><td class="code"><pre><span class="line"><span class="tag"><<span class="name">bean</span> <span class="attr">id</span>=<span class="string">"dataSource"</span> <span class="attr">class</span>=<span class="string">"com.mchange.v2.c3p0.ComboPooledDataSource"</span> <span class="attr">destroy-method</span>=<span class="string">"close"</span>></span></span><br><span class="line"><span class="tag"><<span class="name">property</span> <span class="attr">name</span>=<span class="string">"driverClass"</span>></span><span class="tag"><<span class="name">value</span>></span>oracle.jdbc.driver.OracleDriver<span class="tag"></<span class="name">value</span>></span><span class="tag"></<span class="name">property</span>></span></span><br><span class="line"><span class="tag"><<span class="name">property</span> <span class="attr">name</span>=<span class="string">"jdbcUrl"</span>></span><span class="tag"><<span class="name">value</span>></span>jdbc:oracle:thin:@localhost:1521:Test<span class="tag"></<span class="name">value</span>></span><span class="tag"></<span class="name">property</span>></span></span><br><span class="line"><span class="tag"><<span class="name">property</span> <span class="attr">name</span>=<span class="string">"user"</span>></span><span class="tag"><<span class="name">value</span>></span>Kay<span class="tag"></<span class="name">value</span>></span><span class="tag"></<span class="name">property</span>></span></span><br><span class="line"><span class="tag"><<span class="name">property</span> <span class="attr">name</span>=<span class="string">"password"</span>></span><span class="tag"><<span class="name">value</span>></span>root<span class="tag"></<span class="name">value</span>></span><span class="tag"></<span class="name">property</span>></span></span><br><span class="line"><span class="comment"><!--连接池中保留的最小连接数。--></span></span><br><span class="line"><span class="tag"><<span class="name">property</span> <span class="attr">name</span>=<span class="string">"minPoolSize"</span> <span class="attr">value</span>=<span class="string">"10"</span> /></span></span><br><span class="line"><span class="comment"><!--连接池中保留的最大连接数。Default: 15 --></span></span><br><span class="line"><span class="tag"><<span class="name">property</span> <span class="attr">name</span>=<span class="string">"maxPoolSize"</span> <span class="attr">value</span>=<span class="string">"100"</span> /></span></span><br><span class="line"><span class="comment"><!--最大空闲时间,1800秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 --></span></span><br><span class="line"><span class="tag"><<span class="name">property</span> <span class="attr">name</span>=<span class="string">"maxIdleTime"</span> <span class="attr">value</span>=<span class="string">"1800"</span> /></span></span><br><span class="line"><span class="comment"><!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 --></span></span><br><span class="line"><span class="tag"><<span class="name">property</span> <span class="attr">name</span>=<span class="string">"acquireIncrement"</span> <span class="attr">value</span>=<span class="string">"3"</span> /></span></span><br><span class="line"><span class="tag"><<span class="name">property</span> <span class="attr">name</span>=<span class="string">"maxStatements"</span> <span class="attr">value</span>=<span class="string">"1000"</span> /></span></span><br><span class="line"><span class="tag"><<span class="name">property</span> <span class="attr">name</span>=<span class="string">"initialPoolSize"</span> <span class="attr">value</span>=<span class="string">"10"</span> /></span></span><br><span class="line"><span class="comment"><!--每60秒检查所有连接池中的空闲连接。Default: 0 --></span></span><br><span class="line"><span class="tag"><<span class="name">property</span> <span class="attr">name</span>=<span class="string">"idleConnectionTestPeriod"</span> <span class="attr">value</span>=<span class="string">"60"</span> /></span></span><br><span class="line"><span class="comment"><!--定义在从数据库获取新连接失败后重复尝试的次数。Default: 30 --></span></span><br><span class="line"><span class="tag"><<span class="name">property</span> <span class="attr">name</span>=<span class="string">"acquireRetryAttempts"</span> <span class="attr">value</span>=<span class="string">"30"</span> /></span></span><br><span class="line"><span class="tag"><<span class="name">property</span> <span class="attr">name</span>=<span class="string">"breakAfterAcquireFailure"</span> <span class="attr">value</span>=<span class="string">"true"</span> /></span></span><br><span class="line"><span class="tag"><<span class="name">property</span> <span class="attr">name</span>=<span class="string">"testConnectionOnCheckout"</span> <span class="attr">value</span>=<span class="string">"false"</span> /></span></span><br><span class="line"><span class="tag"></<span class="name">bean</span>></span></span><br></pre></td></tr></table></figure>
]]></content>
<categories>
<category>Java</category>
</categories>
<tags>
<tag>java</tag>
<tag>c3p0</tag>
</tags>
</entry>
<entry>
<title>JDBC事务处理</title>
<url>/2014/12/30/jdbc-transaction/</url>
<content><![CDATA[<p>在JDBC中,事务操作默认是自动提交。也就是说,一条对数据库的更新表达式代表一项事务操作。操作成功后,系统将自动调用<code>commit()</code>来提交,否则将调用<code>rollback()</code>来回退。<br>可以通过调用<code>setAutoCommit(false)</code>来禁止自动提交。之后就可以把多个数据库操作的表达式作为一个事务,在操作完成后调用<code>commit()</code>来进行整体提交。<br>倘若其中一个表达式操作失败,都不会执行到<code>commit()</code>,并且将产生响应的异常。此时就可以在异常捕获时调用<code>rollback()</code>进行回退。<br>这样做可以保持多次更新操作后,相关数据的一致性。</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment"> * 2014年12月30日16:24:04</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"></span><br><span class="line">Connection conn;</span><br><span class="line">Statement stat;</span><br><span class="line">ResultSet rs;</span><br><span class="line"><span class="keyword">try</span> {</span><br><span class="line"> Class.forName(<span class="string">"oracle.jdbc.driver.OracleDriver"</span>);</span><br><span class="line"> conn = DriverManager.getConnection(<span class="string">"jdbc:oracle:thin:@127.0.0.1:1521:orcl"</span>, <span class="string">"test"</span>, <span class="string">"test"</span>);</span><br><span class="line"> conn.setAutoCommit(<span class="keyword">false</span>);</span><br><span class="line"> stat = conn.createStatement();</span><br><span class="line"></span><br><span class="line"> stat.executeUpdate(<span class="string">"INSERT INTO student VALUES('00001', '老大', '男', '22', 'AA')"</span>);</span><br><span class="line"> stat.executeUpdate(<span class="string">"INSERT INTO student VALUES('00002', '老二', '女', '42', 'BB')"</span>);</span><br><span class="line"></span><br><span class="line"> conn.commit();</span><br><span class="line"> conn.setAutoCommit(<span class="keyword">true</span>);</span><br><span class="line">} <span class="keyword">catch</span> (ClassNotFoundException e) {</span><br><span class="line"> e.printStackTrace();</span><br><span class="line">} <span class="keyword">catch</span> (SQLException e) {</span><br><span class="line"> e.printStackTrace();</span><br><span class="line"> <span class="keyword">try</span> {</span><br><span class="line"> conn.rollback();</span><br><span class="line"> System.out.println(<span class="string">"回滚成功"</span>);</span><br><span class="line"> conn.setAutoCommit(<span class="keyword">true</span>);</span><br><span class="line"> } <span class="keyword">catch</span> (SQLException e1) {</span><br><span class="line"> e1.printStackTrace();</span><br><span class="line"> }</span><br><span class="line">} <span class="keyword">finally</span> {</span><br><span class="line"> <span class="keyword">try</span> {</span><br><span class="line"> <span class="keyword">if</span> (rs != <span class="keyword">null</span>) {</span><br><span class="line"> rs.close();</span><br><span class="line"> }</span><br><span class="line"> } <span class="keyword">catch</span> (SQLException e) {</span><br><span class="line"> e.printStackTrace();</span><br><span class="line"> } <span class="keyword">finally</span> {</span><br><span class="line"> <span class="keyword">try</span> {</span><br><span class="line"> <span class="keyword">if</span> (stat != <span class="keyword">null</span>) {</span><br><span class="line"> stat.close();</span><br><span class="line"> }</span><br><span class="line"> } <span class="keyword">catch</span> (SQLException e) {</span><br><span class="line"> e.printStackTrace();</span><br><span class="line"> } <span class="keyword">finally</span> {</span><br><span class="line"> <span class="keyword">try</span> {</span><br><span class="line"> <span class="keyword">if</span> (conn != <span class="keyword">null</span>) {</span><br><span class="line"> conn.close();</span><br><span class="line"> }</span><br><span class="line"> } <span class="keyword">catch</span> (SQLException e) {</span><br><span class="line"> e.printStackTrace();</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
]]></content>
<categories>
<category>Java</category>
</categories>
<tags>
<tag>java</tag>
<tag>jdbc</tag>
</tags>
</entry>
<entry>
<title>CentOS7编译安装git并配置使用github</title>
<url>/2014/12/26/centos7-git-github/</url>
<content><![CDATA[<h2 id="一、编译安装git"><a href="#一、编译安装git" class="headerlink" title="一、编译安装git"></a>一、编译安装git</h2><p>CentOS7默认安装的git版本为1.8.3.1,而git官方的版本已经到2.2.0了,所以选择下载源码编译安装git</p>
<h3 id="1-clone-github上的git源码"><a href="#1-clone-github上的git源码" class="headerlink" title="1.clone github上的git源码"></a>1.clone github上的git源码</h3><p><code>$ git clone https://github.com/git/git.git</code></p>
<h3 id="2-进入git目录进行配置及安装"><a href="#2-进入git目录进行配置及安装" class="headerlink" title="2.进入git目录进行配置及安装"></a>2.进入git目录进行配置及安装</h3><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">$ cd git</span><br><span class="line">$ autoconf</span><br><span class="line">$ ./configure</span><br><span class="line">$ make</span><br><span class="line">$ make install</span><br></pre></td></tr></table></figure>
<p>期间可能会提示缺少文件,是因为git的依赖包没有安装,缺什么装什么就好,或者直接<br><code>yum -y install curl curl-devel zlib-devel openssl-deve perl perl-devel cpio expat-devel gettext-deve</code></p>
<h3 id="3-查看版本"><a href="#3-查看版本" class="headerlink" title="3.查看版本"></a>3.查看版本</h3><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">$ git --version</span><br><span class="line">git version 1.8.3.1</span><br></pre></td></tr></table></figure>
<p>竟然还是原来的版本而不是最新安装的2.2.0,那只能先把旧版本卸载了</p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">$ rpm -q git</span><br><span class="line">git-1.8.3.1-4.el7.x86_64</span><br><span class="line">$ sudo rpm -e --nodeps git-1.8.3.1-4.el7.x86_64</span><br></pre></td></tr></table></figure>
<p>然后执行<br><code>sudo ln -s /usr/local/bin/* /usr/bin/</code><br>再次查看git版本</p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">$ git --version</span><br><span class="line">git version 2.2.0.GIT</span><br></pre></td></tr></table></figure>
<p>git版本已经是我们新安装的2.2.0了</p>
<h3 id="4-设置自己的用户名和邮箱"><a href="#4-设置自己的用户名和邮箱" class="headerlink" title="4.设置自己的用户名和邮箱"></a>4.设置自己的用户名和邮箱</h3><p>命令行输入:(引号加不加无所谓)</p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">$ git config --global user.name "Your Name"</span><br><span class="line">$ git config --global user.email "[email protected]"</span><br></pre></td></tr></table></figure>
<h3 id="5-在本地创建仓库并初始化"><a href="#5-在本地创建仓库并初始化" class="headerlink" title="5.在本地创建仓库并初始化"></a>5.在本地创建仓库并初始化</h3><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">$ mkdir test</span><br><span class="line">$ cd test</span><br><span class="line">$ git init</span><br></pre></td></tr></table></figure>
<p>初始化空的 Git 版本库于 <code>/home/username/github/test/.git/</code><br>至此git安装完成</p>
<h2 id="二、使用github"><a href="#二、使用github" class="headerlink" title="二、使用github"></a>二、使用github</h2><p>1.注册github账号</p>
<p>我这里创建了一个账号:<code>SinalVee</code>,并创建了一个<code>Test</code>仓库用于测试</p>
<p>2.用ssh-kengen生成公钥</p>
<p><code>$ ssh-keygen -t rsa -C [email protected]</code><br><a href="mailto:[email protected]">[email protected]</a>为你的邮箱地址</p>
<p>设定存放目录和密码后在github设置中找到SSH Keys,选择Add SSH Key,设置名称并把<code>*/.ssh/id_rsa.pub</code>的文件内容粘贴进去</p>
<p>3.测试是否成功</p>
<p><code>$ ssh -T [email protected]</code><br>出现下面的信息并提示验证私钥则成功,输入密码解锁私钥</p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">The authenticity of host 'github.com (192.30.252.130)' can't be established.</span><br><span class="line">RSA key fingerprint is 16:27:ac:axxxxxxxxxxxxxxxxx:df:a6:48.</span><br><span class="line">Are you sure you want to continue connecting (yes/no)? yes</span><br><span class="line">Warning: Permanently added 'github.com,192.30.252.130' (RSA) to the list of known hosts.</span><br><span class="line">Hi SinalVee! You've successfully authenticated, but GitHub does not provide shell access.</span><br></pre></td></tr></table></figure>
<p>在本地任意目录新建同步文件夹</p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">$ mkdir github</span><br><span class="line">$ cd github</span><br><span class="line">$ git clone [email protected]:SinalVee/Test(此处SinalVee为用户名,Test是你在github上创建的仓库)</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">正克隆到 'Test'...</span><br><span class="line">Warning: Permanently added the RSA host key for IP address '192.30.252.131' to the list of known hosts.</span><br><span class="line">remote: Counting objects: 6, done.</span><br><span class="line">remote: Total 6 (delta 0), reused 0 (delta 0)</span><br><span class="line">接收对象中: 100% (6/6), 完成.</span><br><span class="line">检查连接... 完成。</span><br></pre></td></tr></table></figure>
<p>因为我很久之前就创建了这个Test仓库并测试过,所以这里共有6个objects(一共两个文件,之所以这里是6是因为Git跟踪并管理的是修改,而非文件)。</p>
<p>接下来测试以下上传</p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">$ cd Test/</span><br><span class="line">$ ls</span><br><span class="line">README.md test.txt</span><br><span class="line">$ touch hello.txt</span><br><span class="line">$ vim hello.txt</span><br><span class="line">你好,这是一个测试文件。</span><br><span class="line">$ ls</span><br><span class="line">hello.txt README.md test.txt</span><br><span class="line">$ git add hello.txt</span><br><span class="line">$ git commit -m "add file hello.txt"</span><br><span class="line">[master 0e4004c] add file hello.txt</span><br><span class="line"> 1 file changed, 1 insertion(+)</span><br><span class="line"> create mode 100644 hello.txt</span><br><span class="line">$ git push</span><br><span class="line">对象计数中: 3, 完成.</span><br><span class="line">Delta compression using up to 4 threads.</span><br><span class="line">压缩对象中: 100% (2/2), 完成.</span><br><span class="line">写入对象中: 100% (3/3), 354 bytes | 0 bytes/s, 完成.</span><br><span class="line">Total 3 (delta 0), reused 0 (delta 0)</span><br><span class="line">To [email protected]:sinalvee/Test</span><br><span class="line"> 984cabc..0e4004c master -> master</span><br></pre></td></tr></table></figure>
<p>在github的网页上刷新一下仓库,发现hello.txt已经上传成功了,至此我们的github已经配置成功,并可以使用了。</p>
<p>github的使用这里不多赘述了。</p>
]]></content>
<categories>
<category>Linux</category>
<category>CentOS</category>
</categories>
<tags>
<tag>linux</tag>
<tag>centos</tag>
<tag>git</tag>
<tag>github</tag>
</tags>
</entry>
<entry>
<title>CentOS7安装SQL Developer读条后闪退解决方案</title>
<url>/2014/12/26/centos7-sqldeveloper/</url>
<content><![CDATA[<p>问题描述:</p>
<p>在CentOS7下安装了sqldeveloper,启动时读条后闪退</p>
<p>sudo执行正常启动</p>
<p>错误信息:</p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">[xxx@xxx sqldeveloper]$ ./sqldeveloper.sh</span><br><span class="line"></span><br><span class="line"> Oracle SQL Developer</span><br><span class="line"> Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.</span><br><span class="line"></span><br><span class="line"> LOAD TIME : 525#</span><br><span class="line"># A fatal error has been detected by the Java Runtime Environment:</span><br><span class="line">#</span><br><span class="line"># SIGSEGV (0xb) at pc=0x00007f94149ab140, pid=19381, tid=140274573408000</span><br><span class="line">#</span><br><span class="line"># JRE version: Java(TM) SE Runtime Environment (7.0_71-b14) (build 1.7.0_71-b14)</span><br><span class="line"># Java VM: Java HotSpot(TM) 64-Bit Server VM (24.71-b01 mixed mode linux-amd64 compressed oops)</span><br><span class="line"># Problematic frame:</span><br><span class="line"># C 0x00007f94149ab140</span><br><span class="line">#</span><br><span class="line"># Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again</span><br><span class="line">#</span><br><span class="line"># An error report file with more information is saved as:</span><br><span class="line"># /tmp/hs_err_pid19381.log</span><br><span class="line">#</span><br><span class="line"># If you would like to submit a bug report, please visit:</span><br><span class="line"># http://bugreport.sun.com/bugreport/crash.jsp</span><br><span class="line">#</span><br><span class="line">/opt/sqldeveloper/sqldeveloper/bin/../../ide/bin/launcher.sh: 行 1193: 19381 已放弃 (吐核)${JAVA} "${APP_VM_OPTS[@]}" ${APP_ENV_VARS} -classpath ${APP_CLASSPATH} ${APP_MAIN_CLASS} "${APP_APP_OPTS[@]}"</span><br></pre></td></tr></table></figure>
<p>解决方案:</p>
<p>进入<code>{sqldeveloper_home}/sqldeveloper/bin/</code>目录,编辑该目录下的sqldeveloper文件,添加如下两行:</p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">unset GNOME_DESKTOP_SESSION_ID</span><br><span class="line">unset DBUS_SESSION_BUS_ADDRESS</span><br></pre></td></tr></table></figure>
<p>再次运行./sqldeveloper.sh,问题解决,成功运行。</p>
]]></content>
<categories>
<category>Linux</category>
<category>CentOS</category>
</categories>
<tags>
<tag>linux</tag>
<tag>centos</tag>
</tags>
</entry>
<entry>
<title>Maven仓库中添加Oracle JDBC驱动</title>
<url>/2014/12/18/maven-oracle-jdbc-driver/</url>
<content><![CDATA[<p>原文地址:<a href="http://maosheng.iteye.com/blog/2001615" target="_blank" rel="noopener">http://maosheng.iteye.com/blog/2001615</a></p>
<p>由于Oracle授权问题,Maven不提供Oracle JDBC driver,为了在Maven项目中应用Oracle JDBC driver,必须手动添加到本地仓库。</p>
<h2 id="一-获得Oracle-JDBC-Driver"><a href="#一-获得Oracle-JDBC-Driver" class="headerlink" title="一.获得Oracle JDBC Driver"></a>一.获得Oracle JDBC Driver</h2><p>1.通过Oracle官方网站下载相应版本:<a href="http://www.oracle.com/technetwork/database/features/jdbc/index-091264.html" target="_blank" rel="noopener">http://www.oracle.com/technetwork/database/features/jdbc/index-091264.html</a></p>
<p>2.通过Oracle的安装目录获得,位置在“{ORACLE_HOME}jdbclibojdbc14.jar”</p>
<h2 id="二-手动安装到本地仓库"><a href="#二-手动安装到本地仓库" class="headerlink" title="二.手动安装到本地仓库"></a>二.手动安装到本地仓库</h2><p>命令如下:</p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc14 -Dversion=10.2.0.1.0 -Dpackaging=jar -Dfile=D:ojdbc14.jar</span><br></pre></td></tr></table></figure>
<h2 id="三-在pom-xml文件中添加引用"><a href="#三-在pom-xml文件中添加引用" class="headerlink" title="三.在pom.xml文件中添加引用"></a>三.在pom.xml文件中添加引用</h2><figure class="highlight xml"><table><tr><td class="code"><pre><span class="line"><span class="tag"><<span class="name">dependency</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">groupId</span>></span>com.oracle<span class="tag"></<span class="name">groupId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">artifactId</span>></span>ojdbc14<span class="tag"></<span class="name">artifactId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">version</span>></span>10.2.0.1.0<span class="tag"></<span class="name">version</span>></span></span><br><span class="line"><span class="tag"></<span class="name">dependency</span>></span></span><br></pre></td></tr></table></figure>
<p>之后就可以正常引用了。</p>