SUCHMOKUO/node-worker-threads-pool

this.require in worker thread can't find module unless running from project directory

jaapie opened this issue · 2 comments

Hi,

I'm creating an API with nodejs + express etc. I am using this library for handling a situation where I need worker thread management. I am running the app in production as a systemd service on Ubuntu, where the command to start the app is: node /opt/projectname. Node starts the app and it runs fine. The problem occurs when I trigger the use of a worker thread which requires an external library (in this case axios).

I have a staticPool set up. If I try to use this.require in the wortker thread function while running the code from another directory—that is, not the project directory—the module cannot be found. When running from the project directory everything is fine.

Setting the WorkingDirectory to the project directory in the systemd unit file stops this issue, but I wanted to make you aware that this issue exists, and possibly document the solution for future users of this library.

Thanks for this great library.

Jaapie

@jaapie Thanks for the information! I'll take a look later.

Any updates on this?