node pm2-dev 运行 index.js 出现错误并且没有启动服务器

node pm2-dev run index.js get error and doesn't start the server

如果我运行

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);
                });

    }
);

有什么问题吗?

在"pm2-dev" pm2 跟踪项目文件夹中的所有更改(选项 --watch 已启用)。并且服务器会在"something has changed"事件的情况下自动重启。项目文件夹中存储日志的文件夹。应用程序写入日志。服务器重新启动。

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