FoalTS / foal

Full-featured Node.js framework, with no complexity. 🚀 Simple and easy to use, TypeScript-based and well-documented.
https://foalts.org/
MIT License
1.88k stars 137 forks source link

Supervisor not working as expected after upgrading from Foal 2 to Foal 4 #1258

Open lcnvdl opened 2 months ago

lcnvdl commented 2 months ago

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.

image

That is not what happens if I run all the Foal V2 projects.

In the next image: All services are working.

image

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\"",
}
LoicPoullain commented 2 months ago

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?

lcnvdl commented 2 months ago

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

lcnvdl commented 2 months ago

I was researching. Supervisor not only is less popular than Nodemon, also, is not mantained:

image

image

Vs nodemon:

image

image

Maybe replacing Supervisor is a good idea.

If you want, I can send you a pull request.

LoicPoullain commented 2 months ago

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:

But perhaps this is something that no longer applies:

(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:

LoicPoullain commented 2 months ago

@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.

lcnvdl commented 2 months ago

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 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.

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" with nodemon.
  • 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.

lcnvdl commented 2 months ago

I'd recommend to start with a completely new fork and "checkouts" your feature branch from

Sure! Thanks for the information