Diligent Dilettante

ZettelKasten part 9

Server-reloading

This is a followup to a previous article, ZettelKasten Part 8

Reload the server when the code changes

Apparently this is simple enough. nodemon claims to do what we need.

yarn add nodemon --dev
yarn global add ts-node typescript @types/node@*

And changing my package.json:

    "server": "nodemon -r source-map-support/register src/index.ts",

Let's give it a try.

user@DESKTOP-AK39L31:~/projects/ZettelKasten$ yarn server
yarn run v1.22.10
$ nodemon -r source-map-support/register src/index.ts
[nodemon] 2.0.7
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: ts,json
[nodemon] starting `ts-node -r source-map-support/register src/index.ts`
listening on http://172.18.118.75:3000
[nodemon] restarting due to changes...
[nodemon] starting `ts-node -r source-map-support/register src/index.ts`
listening on http://172.18.118.75:3000
Error: bad thing happened
at /home/user/projects/ZettelKasten/src/index.ts:96:23
at step (/home/user/projects/ZettelKasten/src/index.ts:33:23)
at Object.next (/home/user/projects/ZettelKasten/src/index.ts:14:53)
at fulfilled (/home/user/projects/ZettelKasten/src/index.ts:5:58)
at processTicksAndRejections (node:internal/process/task_queues:94:5)
[nodemon] restarting due to changes...
[nodemon] starting `ts-node -r source-map-support/register src/index.ts`
listening on http://172.18.118.75:3000

It seems to have worked.

Note it restarts the entire webserver. That's fine by me. If it takes too long to boot up, I probably should be solving that issue rather than trying to get individual modules to reload.