nodejs + nodemon + forever give me an error - node.js

I just installed forever globally (-g). Before that I used to run with
$ npm start
Now after installed forever, I tried to lunch the node app
$ NODE_ENV=development forever nodemon server.js
but I receive this error
warn: --minUptime not set. Defaulting to: 1000ms
warn: --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
error: Cannot start forever
error: script /path/to/app/nodemon does not exist.
the same also with
$ NODE_ENV=development forever nodemon server.js
any idea?

The error you received in your output:
error: script /path/to/app/nodemon does not exist.
It appears that forever is looking for nodemon in the current working directory, and can't find it because it doesn't exist there. Try providing the absolute path when starting nodemon, which can be found with which nodemon.
forever start /usr/local/bin/nodemon server.js
Note that the start flag is what puts the application in daemon mode.

Try this
NODE_ENV=development forever start -c nodemon server.js
The -c is for execute commands, forever send you that error because it's looking for a app called nodeamon, but your app is server.js

Related

Forever dont want to start

I learning NodeJS. I have ubuntu 16 server with installed nodejs. Then i install globally express-generator and forever. Next i maked a folder into /var/www named as hack-it-up.ru and used express-generator to generate the app. Next i changed port of my app as 8081 and tryed to start it with npm start. All works fine. But... when i tryed to start my app with forever, i got errors. I readed lots of guides but didnt solved it. Help me please. Thanks!
root#ashipka:/var/www/hack-it-up.ru# forever start -l /var/www/forever-logs/hack-it.log -a app.js
warn: --minUptime not set. Defaulting to: 1000ms
warn: --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
info: Forever processing file: app.js
root#ashipka:/var/www/hack-it-up.ru# forever list
info: Forever processes running
data: uid command script forever pid id logfile uptime
data: [0] aj4I /usr/local/bin/node app.js 27060 27066 /root/.forever/aj4I.log STOPPED
data: [1] wFf4 /usr/local/bin/node app.js 27147 27153 /var/www/forever-logs/hack-it.log STOPPED
root#ashipka:/var/www/hack-it-up.ru# forever stop 0
error: Forever cannot find process with id: 0
I needed to start from bin/www file instead of app.js as said Mohit Bhardwaj. Thanks! All works fine.

forever with nodemon (command line)

I'm trying to use nodemon with forever.
I have no problems with nodemon alone:
nodemon --exitcrash node/index.js -- "user/verbs/config"
However, in following the instructions in the nodemon FAQ, and putting quotes around "nodemon --exitcrash" as per the comment at https://stackoverflow.com/a/20306929/271577 (to avoid forever thinking the argument "user/verbs/config" is the file) to produce:
forever start --minUptime 1000 --spinSleepTime 1000 --killSignal=SIGTERM -c "nodemon --exitcrash" node/index.js -- "user/verbs/config"
...I get the message
info: Forever processing file: node/index.js
and no continuation of the script. Running forever list shows "No forever processes running".
(Note: I eventually want this working with forever-monitor, but I figure the above will need to work first.)
Is there something I'm missing?
forever -c "nodemon --exitcrash" app.js
this makes sure nodemon actually exits (rather than giving you the "app crashed" message) and then forever picks it up again.
In forever --help this -c specifies a command to run otherwise it defaults node. Without -c results in the error that is mention in the comments to this answer.
Source

nodemon, supervisor, forever all are giving different errors, Any suggestions?

i have tried all the three one by one by installing them globally.
but none seems to work.
I am using these to restart the server automatically when i make any changes.
Following are the commands that i am using.
nodemon npm start
forever npm start
supervisor npm start
Error from supervisor
Error: Cannot find module 'E:\d v\MEAN Lynda - Developing for the MEAN Stack and
MongoDB\projects\project\start'
at Function.Module._resolveFilename (module.js:339:15)
at Function.Module._load (module.js:290:25)
at Function.Module.runMain (module.js:447:10)
at startup (node.js:142:18)
at node.js:939:3
Program node start exited with code 1
Starting child process with 'node start'
module.js:341
throw err;
^
Error from forever
E:\d v\MEAN Lynda - Developing for the MEAN Stack and MongoDB\projects\project>f
orever npm start
warn: --minUptime not set. Defaulting to: 1000ms
warn: --spinSleepTime not set. Your script will exit if it does not stay up f
or at least 1000ms
error: Cannot start forever
error: script E:\d v\MEAN Lynda - Developing for the MEAN Stack and MongoDB\pr
ojects\project\npm does not exist.
you should check the package.json file where you have properly assigned the value of "start" key or not. Forever and supervisor are used as follows. you can always type and check that using :
forever -h
supervisor -h
you will find the following output as examples of using supervisor:
Examples:
supervisor myapp.js
supervisor myapp.coffee
supervisor -w scripts -e myext -x myrunner myapp
supervisor -- server.js -h host -p port
forever is used as follows:
forever start app.js

Forever not working with sailsjs

I've installed forever using
npm install forever -g
I've set config in modeljs to safe
migrate: 'safe'
Still when I run
forever -w start app.js
I get this
warn: --minUptime not set. Defaulting to: 1000ms
warn: --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
info: Forever processing file: app.js
I dont want to stop and start my app using sails lift everytime I'm making a change. I'm using sails version of 0.11.
Used sails-hook-autoreload in the end which did the same job with ease.

nodejs forever : How to run my npm application

Right now i am runnign my nodejs application as npm start. i want to run it in background. I found forever package for this but dont know how can i run a application that i usually run as npm start. So how can i run it using forever ?
I follow this SO but getting this error:
ENVIRONMENT=production forever start app.js
warn: --minUptime not set. Defaulting to: 1000ms
warn: --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
info: Forever processing file: app.js
apart of this Is there any other better way to run nodejs in background ?
You are doing it right.
The warnings are just reminding you that some essential information is missing, so it assigns the defaults. To be exact, if your script crashes/exits sooner than a second after start, forever will exit as well.
If you would like to get rid of those warnings:
forever start --minUptime 1000 --spinSleepTime 1000 app.js
Furthermore, you can open the package.json file, find the:
"scripts": {
"start": "node app.js"
},
and change it to:
"scripts": {
"start": "forever start --minUptime 1000 --spinSleepTime 1000 app.js",
"stop": "forever stop app.js"
},
Now you can use npm start and it will invoke forever automatically.
In 2022
Use forever npm package ( https://www.npmjs.com/package/forever )
forever start -c "npm <command\>" /path/to/app/dir/
EXAMPLE
./ means current directory
forever start -c "npm start" ./
For Linux
Use terminal and enter in superuser mode, and try these code
$ nohup node <location of of js file> &
$ exit
Note: This '&' is must before you press enter
or for npm command, just goto the location by cd command where your package.json is stored. Then
$ nohup npm start &
$ exit
Note: This '&' is must before you press enter
To stop it
$ top
You can see process id here, then use following code
$ kill -9 <PROCESS_ID>

Resources