Quick tip for Cordova and the Browser platform - Setting a custom port

This post is more than 2 years old.

I'm not regularly using Cordova and the Browser platform because most of the time I'll use ionic serve instead. However, last night I was working on a Cordova project that - shockingly - didn't use Ionic. I needed to run it in a web page to do some quick testing. I quickly discovered that one thing the browser platform does not handle is enabling CORS for all requests. I had set up CORS for the server part of this application a while ago but it required me to use localhost:3333. By default, Cordova will use port 8000 for the port. There wasn't an obvious way to change that so I did some digging.

The first thing I did was go into the browser folder under platforms. Under platforms/browser/cordova I opened up the run file and saw that the script did include the ability to pass in a port argument. I couldn't figure out how to pass it though so I tried doing run -h:


Ok, that's simple. I confirmed it worked by doing cordova/run --port=3333. Sweet. But how do it via the "main" Cordova CLI? If you run cordova help run, you'll see this nugget in the docs:


So basically, this is all you need to do: cordova run browser -- --port=3333. Simple, right? Probably everyone but me knew this, but as I had to dig to figure it out, I thought it made sense to blog it.

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Archived Comments

Comment 1 by Stephan Pieterse posted on 7/28/2016 at 7:18 AM

Did the same digging, just missed the '--' for platform specific options, thanks!

Comment 2 by 鄭嘉鴻 posted on 7/12/2017 at 4:37 PM

does it possible to change default address as well?

Comment 3 (In reply to #2) by Raymond Camden posted on 7/14/2017 at 11:10 PM

Check the CLI arguments - I believe so.

Comment 4 by Peety posted on 9/3/2019 at 7:30 AM

Raymond did you ever get service workers on Android Cordova to work? Run a plugin webserver maybe?

Comment 5 (In reply to #4) by Raymond Camden posted on 9/3/2019 at 3:40 PM

Sorry, never tried and haven't used Cordova in a while.