Search code examples
node.jstypescriptnodemonts-node

How to run nodemon + ts-node + typescript altogether without having to install ts-node or npx globally?


I have the following in my package.json:

  "scripts": {
    "serve-fake-api": "nodemon fake-api/server.ts --watch 'fake-api/*.*'",
    "serve-vue": "vue-cli-service serve",
    "serve": "concurrently -k \"npm run serve-fake-api\" \"npm run serve-vue\"",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
  },

and I would like to rewrite "serve-fake-api": "nodemon --exec 'ts-node' fake-api/server.ts --watch fake-api/*.*", but without having to install ts-node or npx globally.

How can I achieve that?


Solution

  • I have come across ts-node-dev recently, which fuses together ts-node and node-dev.

    No configuration required. CLI arguments are the combination of the ones ts-node and node-dev accepts, and a couple of its own on top of that.

    Run like this:

    "start": "tsnd fake-api/server.ts"