Forever Node.JS Express 4
Asked Answered
D

6

18

How do you run the Express 4 app with Forever? (or is there a new package?)

I am running my Express 3 apps with Forever installed locally with the package manager. I use the command:

forever -a start app.js
Desiderative answered 6/6, 2014 at 1:30 Comment(1)
like magic I post to SO and find something on the next (one million and 1) search: github.com/Unitech/pm2. Is this legit?Desiderative
R
24

Try this:

forever start ./bin/www

Let's take a look to package.json:

"scripts": {
    "start": "node ./bin/www"
},

I guess when we call npm start, ./bin/www will be executed at some point. Then look at the content of./bin/www:

var server = app.listen(app.get('port'), function() {
  debug('Express server listening on port ' + server.address().port);
});

so we are ready to listen for connections.

Resht answered 23/7, 2014 at 15:37 Comment(0)
I
14
forever start --minUptime 1000 --spinSleepTime 1000 ./bin/www
Importune answered 6/11, 2014 at 0:1 Comment(1)
I've seen this answer all over, but no explanation as to how ./bin/www could have any idea at all where your app.js file is, or what it's named.Ticknor
I
2

If you use npm start to run your app, this works in place of it:

forever start -c "npm start" /path/to/app/dir/

Source: https://github.com/foreverjs/forever/issues/540

Iow answered 16/1, 2017 at 4:11 Comment(0)
A
1

Try node app.js first, for me, I added a new module in code base, but i did not run npm install in my AWS box, forever is not giving you the error, it just stopped silently, but node will give you the error

Artemis answered 23/3, 2016 at 22:49 Comment(0)
S
0

http://expressjs.com/guide.html

in Expressjs guide doc,

use 'npm start'

I want use 'forever' but can not too

so,

add code at 'app.js'

var server = app.listen(3000, function() { console.log('Listening on port %d', server.address().port); });

and

$node app.js

can use it.

and forever can use too

Sid answered 7/6, 2014 at 6:50 Comment(3)
I see this got a down vote with no comment. That is not fair. If you think this is wrong say why. I am still using express 3. I tried pm2 but it didn't even 'hello world'.Desiderative
hm... do you $node app.js ? it doesn't start or occur error -> code check, nothing on console -> please check debug or upload your codeSid
@EricSheasby I think the reason this got down voted is because this doesn't answer the question at all. You are asking how to use forever to start a node application and pineoc explicitly says they don't know how in their answer but try to provide an answer anyways.Amoebaean
W
0

Feb 2021

This solution is for express.js & forever, on Windows OS.

package.json

"scripts": {
  "start": "set PORT=3001 && set DEBUG=myapp:* && forever start --minUptime 1000 --spinSleepTime 1000 ./bin/www",
}

Now run:

npm start

NOTE: For other OS, and customization see following link: https://expressjs.com/en/starter/generator.html

Wartow answered 14/2, 2021 at 9:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.