├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── nodev.js ├── options.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | deploy: 3 | api_key: 4 | secure: nmce3MDQycfuGPPXIpgTQsRnwiUxF9MiCjAJT9pcP1sZiy/C/vKlr0Vg0cmch3wQO3nOlgBU9Vlndy2SGxMNPMkCsfyNW1DNCnOjgHT7HMsDi2DHvgpSmhRAh20UD4CtJwWCJ01qiSMsN8HIPU5hut/2W3NAqSHw1iZM2kcDDJs= 5 | email: aleksey.kamensky@gmail.com 6 | provider: npm 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Alexey Kamenskiy 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/akamensky/nodev.svg?branch=master)](https://travis-ci.org/akamensky/nodev) 2 | [![Dependency Status](https://david-dm.org/akamensky/nodev.svg)](https://david-dm.org/akamensky/nodev) 3 | 4 | # Description 5 | 6 | Nodev is a wrapper for `nodemon` and `node-inspector`. It will automatically start Node.js process in debug mode and start node-inspector attached to it. 7 | 8 | # Installation 9 | 10 | ```sh 11 | $ sudo npm install -g nodev 12 | ``` 13 | 14 | # Usage 15 | 16 | Start with default settings: 17 | 18 | ```sh 19 | $ nodev ./app.js 20 | ``` 21 | This will start your script as Node.js application with `--debug=7000` option. To start application paused at first line use: 22 | ```sh 23 | $ nodev --debug-brk ./app.js 24 | ``` 25 | This will start your application as if it was executed with `--debug-brk=7000` option. 26 | 27 | # What doesn't work 28 | See full list of open tickets here : https://github.com/akamensky/nodev/issues I'll be happy to accept pull requests closing those tickets. 29 | -------------------------------------------------------------------------------- /nodev.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 'use strict'; 3 | 4 | var nodemon = require('nodemon'); 5 | var ps = require('portscanner'); 6 | var async = require('async'); 7 | var fork = require('child_process').fork; 8 | 9 | var options = require('./options'); 10 | 11 | var inspector = false; 12 | 13 | var debug_port = 0; 14 | var web_port = 0; 15 | 16 | async.series([find_ports, main_part]); 17 | 18 | 19 | function find_ports(callback){ 20 | ps.findAPortNotInUse(options.port_range_start, options.port_range_end, '127.0.0.1', function(err, port){ 21 | debug_port = port; 22 | ps.findAPortNotInUse(debug_port+1, options.port_range_end, '127.0.0.1', function(err, port){ 23 | web_port = port; 24 | callback(); 25 | }); 26 | }); 27 | } 28 | 29 | 30 | function main_part(callback){ 31 | 32 | process.argv = process.argv.slice(2); 33 | 34 | var new_args = []; 35 | var debug_set_flag = false; 36 | for(var i=0; i < process.argv.length; i++){ 37 | var arg = process.argv[i]; 38 | if(arg.indexOf('--debug-brk') == 0 && debug_set_flag == false){ 39 | new_args.push('--debug-brk='+debug_port); 40 | debug_set_flag = true; 41 | }else if(arg.indexOf('--debug') == 0 && debug_set_flag == false){ 42 | new_args.push('--debug='+debug_port); 43 | debug_set_flag = true; 44 | } else { 45 | new_args.push(arg); 46 | } 47 | } 48 | 49 | if(!debug_set_flag){ 50 | new_args.unshift('--debug='+debug_port); 51 | } 52 | 53 | process.argv = new_args; 54 | 55 | var str = ' '; 56 | for(var i=0; i < process.argv.length; i++){ 57 | str += process.argv[i] + ' '; 58 | } 59 | 60 | nodemon(str); 61 | 62 | nodemon.on('start', function(){ 63 | if(inspector != false) return; 64 | var inspectorArgs = ['--debug-port='+debug_port, '--web-port='+web_port, '--no-preload', '--save-live-edit']; 65 | var forkOptions = { silent: false }; 66 | inspector = fork( 67 | require.resolve('node-inspector/bin/inspector'), 68 | inspectorArgs, 69 | forkOptions 70 | ); 71 | }).on('restart', function(){ 72 | console.warn('Please refresh node-inspector window...'); 73 | }).on('quit',function(){ 74 | 75 | }); 76 | callback(); 77 | } 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /options.js: -------------------------------------------------------------------------------- 1 | var options = { 2 | port_range_start:7000, 3 | port_range_end:7999, 4 | }; 5 | 6 | module.exports = options; 7 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nodev", 3 | "version": "0.8.8", 4 | "description": "Auto re-loading of node apps with node-inspector", 5 | "homepage": "http://akamensky.github.io/nodev/", 6 | "author": { 7 | "name": "Eric Vicenti", 8 | "url": "http://github.com/ericvicenti" 9 | }, 10 | "contributors": [ 11 | { 12 | "name": "Alexey Kamenskiy", 13 | "email": "aleksey.kamensky@gmail.com", 14 | "url": "http://github.com/akamensky/" 15 | } 16 | ], 17 | "keywords": [ 18 | "monitor", 19 | "development", 20 | "restart", 21 | "autoload", 22 | "reload", 23 | "debug", 24 | "node-inspector", 25 | "dev", 26 | "inspector", 27 | "console" 28 | ], 29 | "repository": { 30 | "type": "git", 31 | "url": "http://github.com/akamensky/nodev.git" 32 | }, 33 | "engines": { 34 | "node": ">=0.8.0" 35 | }, 36 | "bin": { 37 | "nodev": "./nodev.js" 38 | }, 39 | "dependencies": { 40 | "async": "^1.5.2", 41 | "node-inspector": "^0.12.7", 42 | "nodemon": "^1.9.1", 43 | "portscanner": "^1.0.0" 44 | }, 45 | "preferGlobal": true, 46 | "licenses": [ 47 | { 48 | "type": "MIT", 49 | "url": "http://rem.mit-license.org" 50 | } 51 | ], 52 | "main": "./nodev" 53 | } 54 | --------------------------------------------------------------------------------