主管节点.js“程序节点应用程序退出代码0”错误 [英] Supervisor node .js "Program node app exited with code 0" error
问题描述
当我安装快速脚手架应用程序
When I install an express scaffold app
express
然后运行npm安装
npm install
然后运行主管
supervisor app
我得到
Starting child process with 'node app'
Program node app exited with code 0
app.js文件是一个基本的默认快递实例。
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);
/// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
/// error handlers
// development error handler
// will 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 to user
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});
module.exports = app;
推荐答案
发电机创建呼叫的应用程序 ./ bin / www
包括 app.js
,然后开始侦听流量。
The app that the generator creates calls ./bin/www
that includes app.js
and then starts listening for traffic.
app.js
不会自己执行。
我认为这很重要。
app.listen
在应用程序中调用不 .js
,但是在 ./ bin / www
中调用...这就是为什么你得到 exit 0
结果。当您调用 app.js
而不是 ./ bin / www
时,它会运行该文件,但因为没有命令监听流量,程序正常结束... ie没有做任何事情。
app.listen
is not being called in app.js
but is called in ./bin/www
...and this is why you get the exit 0
result. When you call app.js
and not ./bin/www
it runs through the file but because is no command to listen for traffic, the program ends normally...i.e. without having done anything.
说,你有两个选择..
That said, you have two options..
选项1
如果你有一个 ./ bin / www
文件,你可以运行
If you have a ./bin/www
file, you could run supervisor ./bin/www
to get things started.
选项2
如果您因为任何原因没有 ./ bin / www
文件,您可以编辑您的应用程序文件看起来像这样。
If you don't have the ./bin/www
file for whatever reason, you can edit your app file to look like this.
在您的应用列表中,替换
In your app listing, replace
module.exports = app;
与此
app.set('port', process.env.PORT || 3000);
var server = app.listen(app.get('port'), function() {
debug('Express server listening on port ' + server.address().port);
});
重要提示
虽然该编辑将启动应用程序侦听,但您将不会再收到退出0
,我不能保证该应用不会与其他错误一起崩溃如果其他文件和目录丢失。例如,如果路由
目录不存在,则需要 routes / index
和路由/用户
将失败,其他不良事情会发生。
While that edit will start the app listening and you won't get an exit 0
any more, I cannot guarantee that the app won't crash with some other error if other files and directories are missing. For example, if the routes
directory isn't present, then the declarations requiring routes/index
and routes/users
will fail and other bad things will happen.
这篇关于主管节点.js“程序节点应用程序退出代码0”错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!