【问题标题】:Running node-inspector and node-debug with npm run使用 npm run 运行 node-inspector 和 node-debug
【发布时间】:2016-03-14 19:42:21
【问题描述】:

如何使用npm run 同时运行两个脚本? 首先,我知道 grunt 或 gulp,但我想在没有其他 js 模块的情况下实现它。 为了做到这一点,我有这个脚本:

"scripts": {
  "start": "node ./node/www",
  "nodemon": "./node_modules/.bin/nodemon node/www.js -i './e2e-tests/**' -i './node_modules/**' -i '.idea/**' -i './node/log/**' -w './node/server/**/*' -V -L",
  "nodeInspector": "./node_modules/.bin/node-inspector --save-live-edit=true",
  "debug": "node-debug ./node/www.js",
  "ins": "npm run nodeInspector & npm run debug"
}

我想使用npm run ins 运行,但它只会触发节点检查器。

【问题讨论】:

标签: node.js node-inspector node-debugger


【解决方案1】:

不可能同时运行这两个命令。他们每个人都需要自己的控制台

【讨论】:

  • 对于 windows 我不能这样做,但我看到了一些来自 linux 的屏幕截图。我改用 grunt。
【解决方案2】:

如果node-debug来自node-inspector包,那么你不需要启动一个新的node-inspector实例,node-debug会自动为你启动。

这就是 node-debug 在后台执行的操作 (source code):

  1. 运行节点检查器。
  2. 在调试模式下运行提供的脚本
  3. 打开用户的浏览器,将其指向检查器。

事实上,同时运行node-inspectornode-debug 将无法按预期工作,因为第二个node-inspector 实例将无法连接到第一个实例已经侦听的同一个端口。

【讨论】:

    【解决方案3】:

    我无法在一行上实现它,这就是为什么我改用并发的咕噜声:

    module.exports = function(grunt) {
        grunt.initConfig({
            concurrent: {
                options: {
                    limit: 3,
                    logConcurrentOutput: true
                },
                debug: {
                    tasks: ['node-inspector', 'nodemon:debug'],
                    options: {
                        logConcurrentOutput: true
                    }
                }
            },
            nodemon: {
                dev: {
                    script: "node/www.js",
                    options: {
                        ignore: ['node/public/**'],
                        callback: function (nodemon) {
                            nodemon.on('log', function (event) {
                                console.log(JSON.stringify(event));
                            });
    
                            // opens browser on initial server start
                            nodemon.on('config:update', function () {
                                console.log("nodemon config:update oldu");
                                // Delay before server listens on port
                                setTimeout(function() {
                                    require('open')('http://localhost:3000');
                                }, 1000);
                            });
    
                            // refreshes browser when server reboots
                            nodemon.on('restart', function () {
                                // Delay before server listens on port
                                setTimeout(function() {
                                    //require('fs').writeFileSync('.rebooted', 'rebooted');
                                }, 1000);
                            });
                        }
                    }
                },
                debug: {
                    script: './node/www.js',
                    options: {
                        ignore: ['node/log/*.log','node/public/**','node/views/**','doc/**','e2e-tests/**','.idea'],
                        callback: function (nodemon) {
                            nodemon.on('log', function (event) {
                                console.log("Nodemon debug callback fonksiyonu nodemon.onLog olayı");
                            });
    
                            // opens browser on initial server start
                            nodemon.on('config:update', function () {
                                console.log("Nodemon debug callback fonksiyonu nodemon.onConfig:Update olayı");
                                // Delay before server listens on port
                                setTimeout(function() {
                                    require('open')('http://localhost:3000');
                                    require('open')('http://localhost:1337/debug?port=5858');
                                }, 1000);
                            });
    
                            // refreshes browser when server reboots
                            nodemon.on('restart', function () {
                                console.log("Nodemon debug callback fonksiyonu nodemon.onRestart olayı");
                                // Delay before server listens on port
                                setTimeout(function() {
                                    //require('fs').writeFileSync('.rebooted', 'rebooted');
                                }, 1000);
                            });
                        },
                        nodeArgs: ['--debug'],
                        watch: ['Gruntfile.js', 'node/server', 'package.json']
                    }
                }
            },
            'node-inspector': {
                custom: {
                    options: {
                        'web-port': 1337,
                        'web-host': 'localhost',
                        'debug-port': 5857,
                        'save-live-edit': true,
                        'no-preload': true,
                        'stack-trace-limit': 4,
                        'hidden': ['node_modules']
                    }
                }
            }
        });
    
        require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
    
        // Çalışması test edildi ve iki pencerede hem test hem uygulama açıyor.
        grunt.registerTask('nodemon-debug', ['concurrent:debug']);
    
    };
    

    【讨论】:

      【解决方案4】:

      我设法同时使用脚本从脚本运行 node-inspector 和 nodemon

      https://www.npmjs.com/package/concurrently

      "dev": "npm install && concurrently \"node-inspector --web-port 9090\" \"nodemon --debug .\""

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-08-28
        • 2015-05-11
        • 1970-01-01
        • 2017-11-28
        • 1970-01-01
        • 2014-11-06
        • 2011-09-04
        • 1970-01-01
        相关资源
        最近更新 更多