NodeJs监控工具-nodemon

前言

    相信大家在开发Node.js应用的的时候,都遇到了一个挺让人烦恼的事情,就是每次即使只是小小的修改了一下子代码,那么也得再重新Crtl+c退出来重启,不像在开发php,java等web项目的时候,修改了项目代码,服务器都会自动重启,让我们的改动生效,好在有大神开发了自动重启的工具——nodemon!推荐给大家

简介

    Nodemon 是一款非常实用的工具,用来监控你 node.js 源代码的任何变化和自动重启你的服务器。 Nodemon 是一款完美的开发工具,可以使用 npm 安装。

安装也是非常简单,只需下面一步即可

1
npm install -g nodemon

使用

1
nodemon 文件名.js

例:

1
2
3
4
5
6
C:\Users\92816\Desktop>nodemon 04_staticServer.js
[nodemon] 1.9.2
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node 04_staticServer.js`
server is runnig at port 3000

如果想获得帮助信息,只需nodemon -h

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
C:\Users\92816\Desktop>nodemon -h
Usage: nodemon [options] [script.js] [args]

Options:

-e, --ext ................ extensions to look for, ie. js,jade,hbs.
-x, --exec app ........... execute script with "app", ie. -x "python -v".
-w, --watch dir........... watch directory "dir" or files. use once for
each directory or file to watch.
-i, --ignore ............. ignore specific files or directories.
-q, --quiet .............. minimise nodemon messages to start/stop only.
-V, --verbose ............ show detail on what is causing restarts.
-I, --no-stdin ........... don't try to read from stdin.
-C, --on-change-only ..... execute script on change only, not startup
--no-colors .............. disable color output
-d, --delay n ............ debounce restart for "n" seconds.
--exitcrash .............. exit on crash, allows use of nodemon with daemon
tools like forever.js.
-v, --version ............ current nodemon version.
-h, --help ............... you're looking at it.
--help <topic> ........... help on a specific feature. Try "--help topics".
-- <your args> ........... to tell nodemon stop slurping arguments.

Note: if the script is omitted, nodemon will try to read "main" from
package.json and without a nodemon.json, nodemon will monitor .js, .coffee,
and .litcoffee by default.

To learn more about nodemon.json config: nodemon --help config
See also the sample: https://github.com/remy/nodemon/wiki/Sample-nodemon.json

Examples:

$ nodemon server.js
$ nodemon -w ../foo server.js apparg1 apparg2
$ PORT=8000 nodemon --debug-brk server.js
$ nodemon --exec python app.py
$ nodemon --exec "make build" -e "styl hbs"
$ nodemon app.js -- -v

For more details see http://github.com/remy/nodemon/

结语

    有了这个自动监控重启无疑会提高自己的开发效率,让我们更方便的programming,如果想了解更多,可以访问其官网;