-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using different versions of node via nvm for each app #1034
Comments
It might. The only thing that I think that changing the interpreter should work too (can't test right now):
One of the advantage of this is that it can easily be reproduced in a json file:
|
Works like a charm! The --interpreter option is neat since that way the option is persisted (or can be configured in the json file as you've mentioned). Also the --interpreted way is better since I can always execute pm2 with node 0.12 and only use --interpreter to point to node 0.10 for the app. Whereas in my example above, I'm running pm2 commands with different version of node for each app (which is probably fine, but a bit weird). |
Glad I helped. It's not weird, pm2 is basically forking§ your app, I don't know what clustering would be in this scenario. § Just like you do in the shell |
Yeah, the forking makes sense. But in my first example I'm running Which is why I prefer the --interpreter approach since I can always using the same pm2 for managing my processes. Anyways, thanks for your help! |
Has this been tested to correctly fork the right Node version during the pm2 startup process? |
It does. At least in my setup where i start apps using a json manifest i.e. pm2 start app.json, where app.json contains the exec_interpereter option. |
But cluster mode is not work. |
I can second that. This is broken for cluster mode. nvm(ized) 6.2.0 node and 5.6.0 are my playpartners. |
Tried the @soyuka method but is broken for me. app go to error without logs |
It is now available with the latest PM2 version: {
apps : [{
name : 'API',
script : 'api.js',
interpreter : 'node@6.9.1'
}]
} https://github.com/Unitech/pm2/blob/master/test/fixtures/nvm-node-version/ecosystem.json#L12 |
This definitely works! Thanks |
I haven't got |
@danielduhh See by yourself here, you the |
Does this work for cluster mode as well? |
|
!!! TO ANYONE WHO FINDS THIS THREAD !!! EXAMPLE: --interpreter=/home/user/.nvm/v0.10.28/bin/node |
You should just define the |
Thanks, can you show an example? And how it would work with NODE_ENV= |
pm2.json
|
Thanks, here's my startup for Ghost Blog Running PM2 in node current on NVM and older version of node for Ghost Blog. As it's running an a Raspberry Pi I've disabled logging to ease wear on the SD card.
|
pm2 only work with nvm alias default |
If I'm trying to run a really old app (runs under Node |
If you use NVM you install PM2 under the latest Node then you can run your app in older Node using the interpreter argument (see my example above). You just need to make sure nvm current is latest node (the node version PM2 was installed under) when you run PM2 |
@GenericUK thanks. Yeah, that's what I tried first, but it hasn't been working, so I thought maybe it was because of how old my app was... |
I figured it out! It turns out that the In my particular case, it was the app's reliance on Do you think I should open up a separate issue to describe this particular situation? |
@morphatic Sorry but we don't support node under 0.12 and soon we will also drop the support for 0.12 |
Am I wrong or |
And can I pass |
PM2 just ignores the interpreter and looks for /usr/bin/node I ran |
Just reported on #3639 |
having NVM_DIR defined, i successfully ran |
Is there any difference between |
not work for me. I don't know why pm2 still uses current node version instead of interpreter. this is my case: ecosystem.json app-error.log SyntaxError: Unexpected token import |
@CyrusNG have same error. |
@shinebayar-g I am using pm2@4.5.0. And I tried following commands: then: |
See this. #4877 I think yours is same ? |
import is experimental in node see https://nodejs.org/api/esm.html maybe that you want to use typescript or babel ? see https://pm2.io/docs/runtime/integration/transpilers/ |
I can confirm (different app/setup) that specifying the node version in the config file works for |
Reporting the same as @tralston , |
This seems to work but I am not getting why pm2 can't take the default node version |
For me it still doesn't work. Is there any way to debug what path pm2 is using or why it can't use the correct absolute path? |
@muscaiu Getting the same error using the Interpreter flag. Any progress? |
I found a workaround to use an interpreter. I just put "engines": {
"npm": ">=6.0.0",
"node": ">=14.20.1"
} |
@buraksakalli is that the only way to get pm2 to respect and use the node version that you are trying to get it to use? I am in the same boat and it is using the environment version instead of the one that I am setting in the ecosystem file. |
If this is really not working, try updating pm2 to latest version:
then kill pm2 processes:
and restart the pm2 process. Also make sure to use
|
for some reason it's not working for me, i tried using interpreter with node version 20, but it still picking 16, i have other project in the same machine with node 16 |
Have you tried the pm2 kill hack? |
Here's the setup I'm thinking about.
All my apps run under ubuntu user
app
.The pm2 startup script is configured with USER
app
.app1
needs node 0.10app2
needs node 0.12I do the following
pm2 list
lists both of the apps. If I inspectprocess.version
in each of the apps - they're running the correct node version.Is this a reasonable approach?
The text was updated successfully, but these errors were encountered: