scripting / Scripting-News

I'm starting to use GitHub for work on my blog. Why not? It's got good communication and collaboration tools. Why not hook it up to a blog?
121 stars 10 forks source link

Using forever with recent versions of Node.js #290

Open scripting opened 9 months ago

scripting commented 9 months ago

I use Forever to keep multiple apps running on my servers. It's not something I can easily change.

There's a problem with recent versions of Node, that keep it from working properly, errors like this, appear, and keep my server, pagePark from working properly.

Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency

Or something else isn't working properly. It only happens when I run the code in Forever, when the code runs standalone, everything is fine.

I've read all the threads, but it's not clear if the problem has been resolved. Any help appreciated in figuring out how to make Forever happy with the latest Node. Thanks in advance.

jystervinou commented 9 months ago

Hi,

As suggested by the author of Forever, the easiest* way out might be to switch to Nodemon.

I'm using it and after install with npm, you can just replace "node script.js" with "nodemon script.js" in your server start command.

Hope it helps.

[*] easiest one, after a potential solution for Forever given later below :->

scripting commented 9 months ago

@jystervinou -- thanks for the suggestion of Nodemon. Looks useful and will probably help with one of my servers, but I use forever as an integral part of PagePark, it uses the forever-monitor package to manage apps that it runs. I have used it to create my own Heroku, and Drummer and feedland.org among many other my most recent apps run in that environment. So far they still work, but it may be because I haven't had to restart the servers since the breakage occurred.

I don't know really know exactly what's going wrong, and I want to put off finding out as long as I can because I'm overflowing with interesting projects that need my attention, including one re MySQL that you probably will find interesting. :smile:

Anyway I do appreciate the suggestion, and I will use it for one of my servers, the one that's having serious trouble right now.

jystervinou commented 9 months ago

I've read the thread to bottom. i'll sum it up as if i was a kind of human ChatGPT :->

If some of the servers run node v12, you might not see the error/warning. The problem is caused because more recent versions of node seem less complacent with circular references, that seem present in forever or more probably in one of the deprecated/abandoned modules it depends on.

Fast forward to the last comment : "Forever is correctly working within this warning Accessing non-existent property 'padLevels' of module exports inside circular dependency. For those which mention that forever processes are not running they are probably using forever version < 3.0.0 - in this case you can see in logs The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received type number (xyz) so you must upgrade to forever version v3.0.0 at least. This bug is fixed in v3.0.0 although author does not mention it in changelog"

So i'd check the versions of Forever, upgrading to the most recent version (at least v3.0.X) and checking that an old version of Winston is not used in your projects, that might conflict with a more recent one used in recent versions of Forever.

What is weird is that a warning prevents the script to run at all.

Note : quite a few recommend pm2, so for future servers, that might be an option too. pm2 or nodemon.

Edit: researched a bit between using pm2 and nodemon. i understand nodemon should be used in dev only. pm2 seems better for prod monitoring.

Also : "With the release of the --watch mode feature in Node.js 18 or higher, you can skip using nodemon and just add the --watch mode instead:

node --watch index.js"

That's for reloading the server automatically when you update and save scripts while developing.

scripting commented 9 months ago

@jy, I just created a new server on Digital Ocean with default versions of Node, NPM and Forever.

Node is v18.13.0

NPM is v9.2.0

Forever is v4.0.3.

I've only launched PagePark with Forever. And I did get the padlevels warning.

There is a Winston in PagePark's node_modules folder. Version is v3.11.0.

jystervinou commented 9 months ago

Are they just warnings? Or does it break the app?

scripting commented 9 months ago

I'm testing that now.

scripting commented 9 months ago

Postscript -- I had to give up on the experiment, for reasons having nothing to do with Forever, I was unable to get this experiment to run as-needed, provisioning new servers has never been one of my favorite things to do.

But I wanted to add:

  1. The software in question, PagePark, is so well debugged at this point that it can run for years without needing to be restarted because of an app crash.

  2. I do not want the functionality of automatic restart on an update. I want to be able to control when the servers restart, and always do it manually, so I can handle any unforeseen problems that might come up.

Anyway, thanks to @jystervinou for his humorous and friendly support. Always appreciated. :smile: