diff --git a/lib/serve.js b/lib/serve.js index 4e33340..9a9a688 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -20,8 +20,13 @@ module.exports = async (file, flags, restarting) => { const module = flags.silent ? getModule(file) : log(getModule(file)) const server = serve(module) - // `3000` is the default port - let port = ~~flags.port + const { isNaN } = Number + let port = Number(flags.port) + + if (isNaN(port) || (!isNaN(port) && (port < 1 || port >= 2 ** 16))) { + console.error(`Port option must be a number. Supplied: ${flags.port}`) + process.exit(1) + } // Check if the specified port is already in use (if none // is specified, the default one will be checked)