@@ -18,6 +18,7 @@ process.env.NODE_ENV = 'development';
18
18
require ( 'dotenv' ) . config ( { silent : true } ) ;
19
19
20
20
var chalk = require ( 'chalk' ) ;
21
+ var execSync = require ( 'child_process' ) . execSync ;
21
22
var webpack = require ( 'webpack' ) ;
22
23
var WebpackDevServer = require ( 'webpack-dev-server' ) ;
23
24
var historyApiFallback = require ( 'connect-history-api-fallback' ) ;
@@ -258,6 +259,17 @@ function run(port) {
258
259
runDevServer ( host , port , protocol ) ;
259
260
}
260
261
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
+
261
273
// We attempt to use the default port but if it is busy, we offer the user to
262
274
// run on a different port. `detect()` Promise resolves to the next free port.
263
275
detect ( DEFAULT_PORT ) . then ( port => {
@@ -267,8 +279,11 @@ detect(DEFAULT_PORT).then(port => {
267
279
}
268
280
269
281
clearConsole ( ) ;
282
+ var existingProcess = getProcessNameOnPort ( DEFAULT_PORT ) ;
270
283
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 + '.' ) +
272
287
'\n\nWould you like to run the app on another port instead?' ;
273
288
274
289
prompt ( question , true ) . then ( shouldChangePort => {
0 commit comments