Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0209c21

Browse files
author
亦才
committed
up
1 parent e739622 commit 0209c21

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
---
2+
layout: post
3+
category : NodeJS
4+
tagline: ""
5+
tags : [lib,nodejs,库]
6+
---
7+
{% include JB/setup %}
8+
9+
随着`NodeJS`的流行,越来越多的第三方模块出现,但是当你开发一个好用的工具或者应用的时候,有没有感觉手头上缺少一些利器呢,虽然`node`本身提供了一些api,但是在开发效率上,有些第三方模块更胜一筹,下面说说社区里比较实用的模块.
10+
11+
## 功能类库
12+
13+
### fs-extra(文件操作)
14+
15+
把这个放在第一个说,因为平时操作文件太频繁了,这个绝对可以提高你的开发效率,虽然`node`本身提供`fs`模块,但是在用户体验上还是不行,比如模拟一些`linux`命令`rm -rf`,`cp -r`,或者创建类似`/foo/bar/foo.txt`这样字符串的路径时,正是`fs-extra`的用武之地.
16+
17+
* 安装: `npm install --save fs-extra`
18+
* <a href="https://github.com/jprichardson/node-fs-extra" target="_blank">API文档</a>
19+
20+
下面演示一个简单的api,复制一个文件夹下内容到另一个文件夹下,更多详细请点击上面的文档链接
21+
22+
```js
23+
24+
var fs = require('fs-extra')
25+
26+
fs.copy('/tmp/myfile', '/tmp/mynewfile', function(err) {
27+
if (err) return console.error(err)
28+
console.log("success!")
29+
}) //copies file
30+
31+
fs.copy('/tmp/mydir', '/tmp/mynewdir', function(err) {
32+
if (err) return console.error(err)
33+
console.log("success!")
34+
})
35+
36+
```
37+
38+
### cheerio(jquery实现)
39+
40+
当你想在`node`里实现`jquery`的操作时,或者想在`测试用例`里实现`dom`操作时,`cheerio`正是你的不二选择.
41+
42+
* 安装: `npm install --save cheerio`
43+
* <a href="https://github.com/cheeriojs/cheerio" target="_blank">API文档</a>
44+
45+
下面演示一些它简单的api,查找某个元素的几种方式
46+
47+
```js
48+
49+
// 1.先包装html元素,然后操作dom
50+
var cheerio = require('cheerio'),
51+
$ = cheerio.load('<h2 class="title">Hello world</h2>');
52+
53+
$('h2.title').text('Hello there!');
54+
$('h2').addClass('welcome');
55+
56+
// 2.直接在操作的时候传递html元素
57+
$ = require('cheerio');
58+
$('ul', '<ul id="fruits">...</ul>');
59+
60+
```
61+
62+
## Node版本管理
63+
64+
### n
65+
66+
`n`是一款`node`版本管理工具,使用非常方便,出自`tj`之手
67+
68+
* 安装: `npm install -g n`
69+
* <a href="https://github.com/tj/n" target="_blank">使用文档</a>
70+
71+
### nvm
72+
73+
`nvm`也是一款`node`版本管理工具,跟`n`相比,功能更多,比前者要重,想用哪个就看使用习惯了
74+
75+
* 安装: `npm install -g nvm`
76+
* <a href="https://github.com/creationix/nvm" target="_blank">使用文档</a>
77+
78+
79+
## 开发工具
80+
81+
### node-inspector
82+
83+
`node-inspector`是一款调试工具,非常好用,基于`WebKit Web Inspector`.
84+
85+
* 安装: `npm install -g node-inspector`
86+
* 使用: `node-debug *.js`, 这里需要说下模块名跟运行命令名不一样
87+
* <a href="https://github.com/node-inspector/node-inspector" target="_blank">使用文档</a>
88+
89+
### node-dev
90+
91+
`node-dev`是一款开发工具,用来处理当`require`的文件改变的,重新启动应用,跟`supervisor`,`nodemon`不一样的时,无需配置任何东西,而且使用`node-notifier`来发送桌面消息,包括应用状态改变以及错误信息.
92+
93+
* 安装: `npm install -g node-dev`
94+
* <a href="https://github.com/fgnass/node-dev" target="_blank">使用文档</a>
95+
96+
### nodemon
97+
98+
`nodemon`是一款开发工具,也是用来处理应用文件修改时,重新启动应用,跟`node-dev`不同的时,它配置非常灵活,可以支持多种情况
99+
100+
* 安装: `npm install -g nodemon`
101+
* <a href="https://github.com/remy/nodemon" target="_blank">使用文档</a>
102+
103+
### supervisor
104+
105+
`supervisor``nodemon`比较接近,都是监视应用文件修改时候重启应用程序,但是它在进程`crash`时,也可以重启应用.
106+
107+
* 安装: `npm install supervisor -g`
108+
* <a href="https://github.com/isaacs/node-supervisor" target="_blank">使用文档</a>
109+
110+

0 commit comments

Comments
 (0)