foal
foal copied to clipboard
Supervisor not working as expected after upgrading from Foal 2 to Foal 4
I'm developing a micro-services backend using Foal TS.
In the development environment, I use a "multiple console" runner. I launch every service at the same time.
The problem is that when I run the Foal 4 projects, it never starts, I have to reboot manually the services until it starts working. And, also, it takes sometimes like 10 minutes.
In the next image: Metr is working, Coord, Cred, High, Iden, Logg, Stge and Stor are not working. Mail and Func are not FoalTS services, so please ignore them.
That is not what happens if I run all the Foal V2 projects.
In the next image: All services are working.
I'm sure the problem is Supervisor, because the problem was fixed after replacing it with another tool (a popular tool named nodemon
).
https://www.npmjs.com/package/nodemon
This not only solves the problem, but also starts the project faster.
My new command for npm run dev
is:
{
"dev": "npm run build && concurrently -r \"tsc -p tsconfig.app.json -w\" \"nodemon --delay 2 -w ./build -w ./config -e js,json,yml ./build/index.js\"",
}
Which version of supervisor did you have in Foal 2 and in Foal 4?
Also, what was the command in package.json
in Foal 2 and in Foal 4?
Foal TS 2 command:
{
"develop": "npm run build && concurrently \"tsc -p tsconfig.app.json -w\" \"supervisor -w ./build,./config -e js,json,yml --no-restart-on error ./build/index.js\"",
}
Supervisor version:
{
"supervisor": "~0.12.0",
}
Note: I didn't realize that the only difference was the command, I thought they were different versions too
I was researching. Supervisor not only is less popular than Nodemon, also, is not mantained:
Vs nodemon:
Maybe replacing Supervisor is a good idea.
If you want, I can send you a pull request.
Out of curiosity, what operating system are you running?
The reasons why supervisor
was chosen in the first place rather than nodemon
were the following:
- It has 0 dependencies (and sub-dependencies) which has many advantages like a smaller size of the
node_modules
directory, fewer trouble to deal with when a sub-dependency suddenly breaks things in a minor version, and fewer security vulnerabilities to patch. - And, at the time, when installing
nodemon
, a message was displayed in the terminal asking users to donate money/sponsors to the project, which sort of "polluted" the installation output.
But perhaps this is something that no longer applies:
- As you pointed out,
supervisor
seems no longer to be maintained, which could lead to problems in the future (unpatched vulnerabilities, new versions of Node not being supported). - Installation of
nodemon
no longer displays a "money message". - The output of
npm run dev
is more "beautiful" withnodemon
. - And
nodemon
starts the project faster (based on what you said).
(I don't think popularity is a good criterion for choice though.)
An alternative, which I hope will work one day, would be to use the native node --watch
function. Unfortunately, the --watch-path
option doesn't work on Linux at the moment.
Moving to nodemon
seems to be an interesting choice then, do you want to submit a PR?
They are some stuff that should still work though:
- when a file config file in JSON or YAML is changed, the server should restart,
- when an error is thrown when the server start, the server should not be reloaded indefinitely,
- doc examples with gRPC and GraphQL should be updated and still work.
@lcnvdl if you take this one, I'd recommend to start with a completely new fork and "checkouts" your feature branch from v4-5-0
. The dependency system has been updated in this branch and it will be easier to run npm install nodemon
and npm uninstall supervisor
in @foal/examples
.
Thank you for your answer.
Out of curiosity, what operating system are you running?
Windows 11
The reasons why
supervisor
was chosen in the first place rather thannodemon
were the following:
- It has 0 dependencies (and sub-dependencies) which has many advantages like a smaller size of the
node_modules
directory, fewer trouble to deal with when a sub-dependency suddenly breaks things in a minor version, and fewer security vulnerabilities to patch.
I understand your reasons.
- And, at the time, when installing
nodemon
, a message was displayed in the terminal asking users to donate money/sponsors to the project, which sort of "polluted" the installation output.But perhaps this is something that no longer applies:
- As you pointed out,
supervisor
seems no longer to be maintained, which could lead to problems in the future (unpatched vulnerabilities, new versions of Node not being supported).- Installation of
nodemon
no longer displays a "money message".- The output of
npm run dev
is more "beautiful" withnodemon
.- And
nodemon
starts the project faster (based on what you said).(I don't think popularity is a good criterion for choice though.)
An alternative, which I hope will work one day, would be to use the native
node --watch
function. Unfortunately, the--watch-path
option doesn't work on Linux at the moment.Moving to
nodemon
seems to be an interesting choice then, do you want to submit a PR?
Sure!
They are some stuff that should still work though:
- when a file config file in JSON or YAML is changed, the server should restart,
Ok
- when an error is thrown when the server start, the server should not be reloaded indefinitely,
Ok
- doc examples with gRPC and GraphQL should be updated and still work.
Ok, I never tried that examples, but I will run them before and after the change, in order to get the same results.
I'd recommend to start with a completely new fork and "checkouts" your feature branch from
Sure! Thanks for the information