An old post I know but here's my take on it
Instead of putting NODE_ENV in your task, set a :default_env option.
set :default_env, { NODE_ENV: "test" }
Then you can use the symbol with exec. execute :forever, "other options"
I've also found that there are quirks with paths in forever so, especialy when trying to set a pid file. Try using the -p
option to set the current path and then you don't need to add current path except on pidFile it seems.
Putting it all together
set :default_env, {NODE_ENV: fetch(:application_env), ...}
desc 'Start application'
task :start do
on roles(:app), in: :sequence, wait: 5 do
execute :forever, "start -p #{release_path} -l logs/logs.log -e logs/err.log -o logs/out.log -a --pidFile #{release_path}/pidfile.pid app.js"
end
end
EDIT: as soon as I hit save I remembered I had to mention that I am talking about Capistrano 3 in case you were not.