Ts-node: Susgestion: Add --watch option

Created on 28 Apr 2016  路  13Comments  路  Source: TypeStrong/ts-node

Add --watch option

for restarting the process when code changed

invalid

Most helpful comment

@niedzielski you may just try ts-node-dev this is modified version of node-dev (which is the fastest node watcher/reloader) that uses ts-node for compilation and it doesn't reinitialize whole compilation process on each change like nodemon -e ts -x ts-node

All 13 comments

No, you should probably be using an actual process manager instead.

@twoeo you may try to use this version of node-dev + ts-node

Thank you for providing this tool! Just curious (and I think the answer is that this functionality is not supported and there are no plans for it) but tsc provides a watch option. When I enabled it via ts-node -O '{ "watch": true }' (or directly in the config file), I was hoping to see the same file monitoring behavior but it seems to have no effect. Is this intentional?

@niedzielski What exactly would a "watch" mode do in your opinion?

@blakeembrey, I was thinking watch would allow tsc to recompile files automatically as per usual and ts-node would wait for compilation completion and automatically shutdown and restart the server for each change. For example, an alternative would be: nodemon -e ts -x ts-node. I realize I'm probably naively missing a lot of detail but I don't think the need is uncommon.

Use nodemon or onchange (mentioned above). This isn't really something that should be supported by ts-node as it'll just create more issues (why does it restart the server instead of reloading a single file, etc). I don't really want to deal with those. It would also complicate the project with the need to watch files, when there's better programs out there already (nodemon, pm2, onchange, etc).

@blakeembrey, thanks for the follow-up and reasoning!

No problem. I honestly did consider having a flag to enable the behaviour, but unfortunately there's runtime and code overhead (watching the files in the project for changes). If it provided a performance benefit (e.g. possible to reload a single file efficiently in node.js) without significant overhead, I'd be willing to revisit the topic.

@niedzielski you may just try ts-node-dev this is modified version of node-dev (which is the fastest node watcher/reloader) that uses ts-node for compilation and it doesn't reinitialize whole compilation process on each change like nodemon -e ts -x ts-node

@whitecolor You should probably get that in the README somewhere 馃槃

@whitecolor thanks!

Good thing about node-dev (ts-node-dev) is that you don't have to specify any files to monitor as any files that were 'require'ed would be automatically monitored but if some are 'require'ed at a later point, it won't be picked up though. You could require them at the start explicitly (assuming they don't do any destructive operations) to just preload them.

Was this page helpful?
0 / 5 - 0 ratings