Skip to content

Commit 8471699

Browse files
Vighnesh K S Ptypicode
Vighnesh K S P
authored andcommitted
Show proper error for PORT in use (typicode#864)
Signed-off-by: VighneshKSP <[email protected]>
1 parent 191539e commit 8471699

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/cli/run.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,20 @@ module.exports = function(argv) {
132132

133133
// Display server informations
134134
prettyPrint(argv, db.getState(), routes)
135+
136+
// Catch and handle any error occurring in the server process
137+
process.on('uncaughtException', error => {
138+
if (error.errno === 'EADDRINUSE')
139+
console.log(
140+
chalk.red(
141+
`Cannot bind to the port ${
142+
error.port
143+
}. Specify some other port number either through --port argument or through the json-server.json configuration file`
144+
)
145+
)
146+
else console.log('Some error occurred', error)
147+
process.exit(1)
148+
})
135149
})
136150
}
137151

0 commit comments

Comments
 (0)