UNPKG

4.29 kBMarkdownView Raw
1# ts-node-dev
2
3> Tweaked version of [node-dev](https://github.com/fgnass/node-dev) that uses [ts-node](https://github.com/TypeStrong/ts-node) under the hood.
4
5It restarts target node process when any of required files changes (as standard `node-dev`) but shares [Typescript](https://github.com/Microsoft/TypeScript/) compilation process between restarts. This significantly increases speed of restarting comparing to `node-dev -r ts-node/register ...`, `nodemon -x ts-node ...` variations because there is no need to instantiate `ts-node` compilation each time.
6
7## Install
8
9![npm (scoped)](https://img.shields.io/npm/v/ts-node-dev.svg?maxAge=86400) [![Build Status](https://travis-ci.org/whitecolor/ts-node-dev.svg?branch=master)](https://travis-ci.org/whitecolor/ts-node-dev)
10
11```
12yarn add ts-node-dev --dev
13```
14
15```
16npm i ts-node-dev --save-dev
17```
18
19`ts-node` dependency version is not fixed, so it will install the latest version by default.
20
21## Usage
22
23```
24ts-node-dev [node-dev|ts-node flags] [ts-node-dev flags] [node cli flags] [--] [script] [script arguments]
25```
26
27So you just combine [node-dev](https://github.com/fgnass/node-dev) and [ts-node](https://github.com/TypeStrong/ts-node) options (see docs of those packages):
28
29```
30ts-node-dev --respawn --transpile-only server.ts
31```
32
33There is also short alias `tsnd` for running `ts-node-dev`:
34
35```
36tsnd --respawn server.ts
37```
38
39Look up flags and options can be used [in ts-node's docs](https://github.com/TypeStrong/ts-node#cli-and-programmatic-options).
40
41**Also there are additional options specific to `ts-node-dev`:**
42
43* `--ignore-watch` - (default: []) - files/folders to be [ignored by `node-dev`](https://github.com/fgnass/node-dev#ignore-paths). **But this behaviour is enhanced:** it also supports regular expression in the ignore strings and will check absolute paths of required files for match.
44
45* `--deps` - Also watch `node_modules`; by default watching is turned off
46
47* `--debug` - Some additional debug output
48* `--interval` - Polling interval (ms) - DOESN'T WORK CURRENTLY
49* `--debounce` - Debounce file change events (ms, non-polling mode)
50* `--clear` (`--cls`) - Will clear screen on restart
51* `--watch` - Explicitly add arbitrary files or folders to watch and restart on change (list separated by commas, [chokidar](https://github.com/paulmillr/chokidar) patterns)
52* `--exit-child` - Adds 'SIGTERM' exit handler in a child process.
53* `--rs` - Allow to restart with "rs" line entered in stdio, disabled by default.
54* `--notify` - to display desktop-notifications (Notifications are only displayed if `node-notifier` is installed).
55
56If you need to detect that you are running with `ts-node-dev`, check if `process.env.TS_NODE_DEV` is set.
57
58
59**Points of notice:**
60
61- If you want desktop-notifications you should install `node-notifier` package and use `--notify` flag.
62
63- Especially for large code bases always consider running with `--transpile-only` flag which is normal for dev workflow and will speed up things greatly. Note, that `ts-node-dev` will not put watch handlers on TS files that contain only types/interfaces (used only for type checking) - this is current limitation by design.
64
65- `--ignore-watch` will NOT affect files ignored by TS compilation. Use `--ignore` option (or `TS_NODE_IGNORE` env variable) to pass **RegExp strings** for filtering files that should not be compiled, by default `/node_modules/` are ignored.
66
67- Unknown flags (`node` cli flags are considered to be so) are treated like string value flags by default. The right solution to avoid ambiguity is to separate script name from option flags with `--`, for example:
68
69 ```
70 ts-node-dev --inspect -- my-script.ts
71 ```
72
73- The good thing is that `ts-node-dev` watches used `tsconfig.json` file, and will reinitialize compilation on its change, but you have to restart the process manually when you update used version of `typescript` or make any other changes that may effect compilation results.
74
75
76## Versioning
77
78Currently versioning is not stable and it is still treated as pre-release. You might expect some options API changes. If you want to avoid unexpected problems it is recommended to fixate the installed version and update only in case of issues, you may consult [CHANGELOG](CHANGELOG.md) for updates.
79
80## License
81
82MIT.
83
\No newline at end of file