Forever Node.JS Express 4

2020-02-17 05:38发布

问题:

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

回答1:

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.



回答2:

forever start --minUptime 1000 --spinSleepTime 1000 ./bin/www


回答3:

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



回答4:

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



回答5:

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