1

I'm trying to use concurrently with nodemon and tsc to have 2 TS scripts be watched, and thus my nodemon server updated when something changes, the index.ts is my router and the queue.ts is a worker. I'm using the following package.json

"dev": "concurrently -k yarn:watch yarn:serve:*",
"watch": "tsc -w",
"serve:index": "nodemon ./build/index.js",
"serve:queue": "nodemon ./build/queue.js"

When running yarn dev I get the following error [serve:*queue] Error: listen EADDRINUSE: address already in use :::3000 even though the queue.js file only contains a console.log

In my index.ts file I'm using express as follows

import express from 'express'

const app = express()
app.use(express.json())

app.listen(3000, () => {
    console.log('Running on 3000...');
    console.log('For the UI, open http://localhost:3000/admin/queues');
});

This is my queue.ts file

console.log('testing');

When the script is not running the port is not in use, I check this by running lsof -i tcp:3000

Miguel Stevens
  • 8,631
  • 18
  • 66
  • 125
  • You are running `yarn:serve:*` concurrently. It probably just executes `serve:index` twice. – Tobias S. Nov 05 '22 at 08:39
  • @TobiasS. I don't think so, it just runs both the serve: scripts, if I change the syntax to `"dev": "concurrently -k yarn:watch yarn:serve:server yarn:serve:db"` the error persists – Miguel Stevens Nov 05 '22 at 08:47
  • @MiguelStevens try using tsx, `tsx watch index.ts`, tsx had a fix for this error iirc – Dimava Nov 05 '22 at 11:35
  • @Dimava tsx instead of tsc? Or tsx in stead of concurrently? In which part do I put the tsx command? – Miguel Stevens Nov 05 '22 at 18:32
  • 1
    @MiguelStevens `tsx watch file.ts` is equivalent of `nodemon --watch '.' exec 'node --inspect --experimental-specifier-resolution=node --loader ts-node/esm/transpile-only ./file.ts` or something. Basically you just run it on TS file and it works. You'll need concurrently `tsx watch src/index.ts` and `tsx watch src/queue.ts` I guess – Dimava Nov 05 '22 at 18:43
  • @MiguelStevens https://github.com/privatenumber/ts-runtime-comparison – Dimava Nov 05 '22 at 18:44
  • @Dimava Thanks! Concurrently is causing issues but I managed to get it running using `tsx watch file.ts & tsx watch otherfile.ts` – Miguel Stevens Nov 11 '22 at 07:08
  • @MiguelStevens please once again check if it was `concurrently` or `nodemod` (IMO nodemon is more likely), so I'll post an answer – Dimava Nov 11 '22 at 08:15
  • I tried using `concurrently tsx watch index.ts tsx watch queue.ts`, I receive the following errors `/bin/sh: watch: command not found, /bin/sh: src/index.ts: Permission denied, /bin/sh: watch: command not found` – Miguel Stevens Nov 11 '22 at 08:20

0 Answers0