node.js - Supervisor node .js "Program node app exited with code 0" error -
when install express scaffold app
express
then run npm install
npm install
and run supervisor
supervisor app
i get
starting kid process 'node app' programme node app exited code 0
the app.js file basic default express instance.
var express = require('express'); var path = require('path'); var favicon = require('static-favicon'); var logger = require('morgan'); var cookieparser = require('cookie-parser'); var bodyparser = require('body-parser'); var routes = require('./routes/index'); var users = require('./routes/users'); var app = express(); // view engine setup app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'jade'); app.use(favicon()); app.use(logger('dev')); app.use(bodyparser.json()); app.use(bodyparser.urlencoded()); app.use(cookieparser()); app.use(express.static(path.join(__dirname, 'public'))); app.use('/', routes); app.use('/users', users); /// grab 404 , forwards error handler app.use(function(req, res, next) { var err = new error('not found'); err.status = 404; next(err); }); /// error handlers // development error handler // print stacktrace if (app.get('env') === 'development') { app.use(function(err, req, res, next) { res.status(err.status || 500); res.render('error', { message: err.message, error: err }); }); } // production error handler // no stacktraces leaked user app.use(function(err, req, res, next) { res.status(err.status || 500); res.render('error', { message: err.message, error: {} }); }); module.exports = app;
the app generator creates calls ./bin/www
includes app.js
, starts listening traffic.
app.js
does not itself.
i think of import understand.
app.listen
not beingness called in app.js
called in ./bin/www
...and why exit 0
result. when phone call app.js
, not ./bin/www
runs through file because no command hear traffic, programme ends normally...i.e. without having done anything.
that said, have 2 options..
option 1
if have ./bin/www
file, run supervisor ./bin/www
things started.
option 2
if don't have ./bin/www
file whatever reason, can edit app file this.
in app listing, replace
module.exports = app;
with this
app.set('port', process.env.port || 3000); var server = app.listen(app.get('port'), function() { debug('express server listening on port ' + server.address().port); });
important note
while edit start app listening , won't exit 0
more, cannot guarantee app won't crash other error if other files , directories missing. example, if routes
directory isn't present, declarations requiring routes/index
, routes/users
fail , other bad things happen.
node.js express supervisor
No comments:
Post a Comment