How to start pm2 with node "-r (module)" or how to deploy a module in node.js?
Asked Answered
U

1

5

Sorry about the question unclarity.

Basically, I need to run my code with -r esm for it to work. With node, I simply do "node -r esm app.js" How could I do the same with PM2? I remember doing it earlier but eh.

I did something like "pm2 start node -r esm app.js" but now it says -r an unknown option. I tried doing "pm2 start app.js -- -r esm" but it didn't solve my problems, it did run the app, but not the esm module.

If someone could either help me with the pm2 command line or with loading the esm module some other way it would be appreciated.

Uncomfortable answered 14/3, 2020 at 8:13 Comment(0)
S
9

It seems you need to use node-args option to specify pm2 that you want to load the esm module:

pm2 start app.js --node-args="-r esm"

This is the recommended syntax from the documentation of esm.

Shelleyshellfire answered 14/3, 2020 at 10:44 Comment(2)
Yes, but I want to load the esm module before the app.js. It's because if I load the app.js before, it throws the "import outside a module" error.Uncomfortable
I don't understand what you mean by "before". node-args pass the option to nodejs at the startup of the script as in your original node -r esm app command.Shelleyshellfire

© 2022 - 2024 — McMap. All rights reserved.