I am new to NodeJS. I tried using my node js application in my local machine, with installing forever module, script runs continuously
But when I deploy my application in VPS(Godaddy). Node application runs fine. I tried installing forever inorder to run my script continuously, with command
npm install forever -g.
It installs the module but when trying to run it with command
forever start app.js
says forever command not found.
Can anyone guide me what am I doing wrong? Any help will be appreciated.
You should check with npm list -g if the module is listed.
Other way to check it is to go to a bash console and type ls /usr/local/lib/node_modules | grep forever and check if the module is there.
If it's not there, something went wrong installing the module. Install it again with sudo npm install -g forever.
Check with printenv | egrep -o "(.*node*) in the bash console and see if you have "NODE_PATH=/opt/lib/node_modules".
If not export NODE_PATH=/opt/lib/node_modules int the console and try again the forever command forever start app.js.
Related
Basically i'm a linux user. For the first time i'm running my node.js application in windows machine. I want to run my application as background process.
So installed forever globally npm install forever -g. Now i tried to run my node application using forever start app.js.
I am receiving error as forever is not reconised as internal or external command.
I tried setting the ENV varibales pointing to bin folder of forever. But still im getting the error.
OS:Windows 7
Please share your ideas.
Package.Json
{
"Name":"xxxx",
"version":"1.0.0",
"dependencies":{
"async":"^2.5.0",
"forever":"^0.15.3"
}
}
Node version: 8.9.3
npm version:5.5.1
I have a problem with a server that runs nodejs.
For some reason, I need to say in the terminal nodejs instead of node.
I try to reinstall it many times, but It doesn't change it.
Now, this isn't a big problem but I need to run forever.
And forever won't run.
Is there a way to call forever with nodejs?
Thanks
According to forever documentation. You can use -c flag to define the command to execute, which default to node.
So if you want to use nodejs instead. You could use forever -c nodejs start script.js
For this to work you need to create a symlink.
For exemple like this :
ln -s /usr/local/bin/nodejs /usr/local/bin/node
install forever as a global
npm install -g forever
and run forever with this command inside application folder as this
forever start server.js
I am trying to install forever to run my nodeJS app. I used npm to install forever
npm install forever -g
now when I try to run my app using the following command, nothing happens (no error message)
forever server.js
when I check pidof forever, I get nothing. What could I be doing wring? The instructions seem fairly straight forward
I've found the solution to this problem. If you used apt-get to install node, it is mapped to nodejs, not node.
head to /usr/local/bin/ and edit forever
vim /usr/local/bin/forever
change this line
#!/usr/bin/env node
to
#!/usr/bin/env nodejs
I am trying to run my nodejs app on an Amazon EC2 instance using forever. I installed nodejs npm, and then ran sudo npm install forever -g.
The installation didn't return any errors, so i go ahead and try running my app using forever start server.js, but it won't do anything - no output what-so-ever, not even an error.
I also tried forever --help and just forever, but none of them giving me any response...
When running my app regularly using nodejs - nodejs init.js then it works as expected, but i need to get it running using forever so it won't shut down when i disconnect from the server.
Edit :
Since the only problem i was having was that nodejs was closing when i closed the terminal session to my EC2 server, I solved this by using the linux nohup command like this :
nohup sudo nodejs server.js &
This kept nodejs running in a child process even after I closed the terminal window.
Thanks for the help though! :)
I was also not receiving any stdout input from any forever command and this fix nailed it:
sudo ln -s /usr/bin/nodejs /usr/local/bin/node
Hope that helps someone.
I don't know if this will help, but as an alternative, you can use upstart. Create a script like this:
#this is the upstart service task. move it to /etc/init/nodeapp.conf
description "server for Node App"
author "Neels Grobler"
chdir /root/servers/nodeapp
exec node init.js 1>stdout.log 2>stderr.log
respawn
And run it by typing start nodeapp. To stop type stop nodeapp. You can also change the script so that the node app starts on system boot etc. More info at upstart.ubuntu.com
You should be using forever start server.js not just forever server.js
Several guesses.
If you install using sudo npm install forever -g, you might need to sudo to run forever.
Put a full path of server.js when you run forever such as forever start /home/you/source/server.js or sudo forever start /home/you/source/server.js
On windows, when you run forever like:
forever start app.js
you can find generated log file in file system at:
C:\Users\USERNAME\.forever\SomeLogFileHere.txt
The log files are regenerated for every running script with unique identicator of each file. You can always check which file belongs to which process by:
forever list
I'm writing an express app in node. I'm trying to crash it but can't... whenever I throw exceptions the app is still running (even when no error handler is configured). I'm using express-resource too if that's related and also streamline.js.
When will something like forever be usefull to me? Is it only in more serious crash like system out of resources?
Forever is useful on development stage. When you hard work on youre code and don't want to handly restart node app. In production it can save your live, when you meet some unexpected error and all project crash ;)
Installation
$ [sudo] npm install forever -g
Note: If you are using forever programmatically you should install forever-monitor.
$ cd /path/to/your/project
$ [sudo] npm install forever-monitor
Usage
There are two ways to use forever: through the command line or by using forever in your code. Note: If you are using forever programatically you should install forever-monitor.
Command Line Usage
You can use forever to run scripts continuously (whether it is written in node.js or not).
Example
forever start app.js