If you use a ecosystem file, add the following lines to your app:
interpreter: '/home/forge/.fnm/fnm',
interpreter_args: 'exec --using=14 node',
14 is the node version. You can be more specific like --using=12.22.4
Example configuration:
module.exports = {
apps : [
{
name: "site",
script: "./index.js",
watch: false,
interpreter: '/home/ubuntu/.fnm/fnm',
interpreter_args: 'exec --using=14 node',
env: {
"NODE_ENV": "production",
},
},
]
}
If you have problems when trying to start global installed modules (like soketi) after a server reboot, try this:
module.exports = {
apps: [
{
name: "soketi",
script: "soketi", // this does not matter anymore but it's required
watch: false,
interpreter: "/usr/bin/bash",
interpreter_args: "-c '/home/ubuntu/.fnm/fnm exec --using=14 soketi start --config=/absolute/path/to/soketi/config.json'",
autorestart: true,
},
],
};
bash -c 'script'
- This fixes the problem by loading the bash profile before executing the script.
Important! Always check if the application starts correctly after a server reboot. Fnm changes the path to the node executable after a reboot and your app will not start after reboot.