node pm2-dev运行index.js得到错误并且不启动服务器

时间:2015-07-23 09:20:38

标签: node.js hapijs pm2

如果我跑

node index.js

我可以看到服务器在http://localhost:8081/

运行

但如果我跑

pm2-dev run index.js

我可以在控制台中看到

[PM2] Streaming realtime logs for [all] processes 

index-0 /home/whisher/myproject/config
index-0 Server started at http://Ugo:8081
PM2 Change detected for app name: index - restarting
PM2 Stopping app:index id:0
PM2 App name:index id:0 exited with code SIGTERM
PM2 Process with pid 9893 killed
PM2 Starting execution sequence in -fork mode- for app name:index id:0
PM2 App name:index id:0 online

index.js

'use strict';

/**
 * Set up ENV for node-config.
 */
process.env.NODE_CONFIG_STRICT_MODE = true;
process.env.NODE_APP_INSTANCE ='development';

/**
 * Module dependencies.
 */
var Config = require('config'),
    Hapi = require('hapi'),
    Boom = require('boom');

/**
 * Lib dependencies.
 */
var Routes = require('./src/routes'),
    port = Config.get('server.port');

/**
 * Set up hapi.
 */
var server = new Hapi.Server();
server.connection({ port: port });

/**
 * Set up router.
 */
for (var route in Routes) {
    server.route(Routes[route]);
}

/**
 * To have reply 422 status.
 */
server.ext('onPreResponse', function (request, reply) {
    var req = request.response;
    if (req.isBoom && (req.output.statusCode===400)) {
            return reply(Boom.badData(req.output.payload.message));
    }
        return reply.continue();
});

var options = {
    opsInterval: 1000,
        reporters: [
            {
                    reporter: require('good-console'),
                    events: { log: '*', response: '*' ,error: '*' ,request: '*' }
            },
            {
                    reporter: require('good-file'),
                    events: { ops: '*' },
                    config: './log/good.log'
            }
        ]
};

server.register(
    {
            register: require('good'),
            options: options
    },
    function (err) {
        if (err) {
                    return console.error(err);
            }
            server.start(function () {
            console.info('Server started at ' + server.info.uri);
                });

    }
);

有什么问题?

1 个答案:

答案 0 :(得分:2)

在" pm2-dev" pm2跟踪项目文件夹中的所有更改(选项 - 启用了监视)。并且在事件的情况下服务器将自动重启"某些事情发生了变化"。包含存储在项目文件夹中的日志的文件夹。应用程序写入日志。服务器重新启动。

将包含日志的文件夹移动到项目文件夹之外。