I am getting a
forever: command not found error when I run a nodejs process using the forever command as a cronjob (in an amazon ec2 machine): the bash script I am using has the following code:
cd to/location/of/the/nodejs/file
forever start file.js
but I am able to run this file by using bash script.sh but I get the forever:command not found error when I run it via cronjob
I am confused dont know what could be the reason for this.
Has anybody else faced this problem?
Thanks in advance
Use npx to solve the error "forever: command not found", e.g. npx forever start app.js or install the package globally by running npm install -g forever to be able to use the command without the npx prefix. The fastest way to solve the error is to use the npx command. Alternatively, you can install forever globally.
The fastest way to solve the error is to use the npx command. Alternatively, you can install forever globally. If the global installation of forever fails, you might have to run the command prefixed with sudo.
In this case foreverwill be installed in the actual install location of nodenot the location of the symbolic link. Share Improve this answer Follow answered May 30 '17 at 12:01 meesernmeesern
This is most likely not where you expect. This may be because nodein your path is a symbolic link. In this case foreverwill be installed in the actual install location of nodenot the location of the symbolic link. Share
Run this command: npm install forever -g
-g
is to install it globally.
For other users who face this problem:
you have to add the path of forever module and then run the script as a cronjob.
In linux the path normally is:
/usr/local/lib/node_modules/forever/bin/forever start file.js
just use this command in your script and the error forever:command not found will not bother you.
I know there must be some other fancy ways to do this but I am happy with this hack
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With