@@ -18,6 +18,7 @@ process.env.NODE_ENV = 'development';
1818require ( 'dotenv' ) . config ( { silent : true } ) ;
1919
2020var chalk = require ( 'chalk' ) ;
21+ var execSync = require ( 'child_process' ) . execSync ;
2122var webpack = require ( 'webpack' ) ;
2223var WebpackDevServer = require ( 'webpack-dev-server' ) ;
2324var historyApiFallback = require ( 'connect-history-api-fallback' ) ;
@@ -258,6 +259,17 @@ function run(port) {
258259 runDevServer ( host , port , protocol ) ;
259260}
260261
262+ function getProcessNameOnPort ( port ) {
263+ var command = 'ps -o command -p "$(lsof -i:' + port + ' -P -t)" | sed -n 2p | tr -d "\n"' ;
264+ var execOptions = { encoding : 'utf8' } ;
265+
266+ try {
267+ return execSync ( command , execOptions ) ;
268+ } catch ( e ) {
269+ return null ;
270+ }
271+ }
272+
261273// We attempt to use the default port but if it is busy, we offer the user to
262274// run on a different port. `detect()` Promise resolves to the next free port.
263275detect ( DEFAULT_PORT ) . then ( port => {
@@ -267,8 +279,11 @@ detect(DEFAULT_PORT).then(port => {
267279 }
268280
269281 clearConsole ( ) ;
282+ var existingProcess = getProcessNameOnPort ( DEFAULT_PORT ) ;
270283 var question =
271- chalk . yellow ( 'Something is already running on port ' + DEFAULT_PORT + '.' ) +
284+ chalk . yellow ( 'Something ' +
285+ ( ( existingProcess ) ? '(probably: ' + existingProcess + ') ' : '' ) +
286+ 'is already running on port ' + DEFAULT_PORT + '.' ) +
272287 '\n\nWould you like to run the app on another port instead?' ;
273288
274289 prompt ( question , true ) . then ( shouldChangePort => {
0 commit comments