options: described below in the following section “launchServer & servePlatform Options“.
Return:
Returns a resolved or rejected promise depending on if the server had launched successfully.
On a fulfilled promise, the following properties are available on the returned object:
Property
Description
serve
The Node http.Server instance.
root
The root that was specified, or cwd if none specified.
port
The port that was used. (Either the requested port, the default port of 8000, or the incremented value of the chosen port when the chosen port is already in use).
servePlatform()
Launches a server that serves up any Cordova platform (e.g. browser, android, etc) from the current project.
options: described below in the following section “launchServer & servePlatform Options“.
Return:
Note that for servePlatform(), the root value should be a Cordova project’s root folder or any folder within it. servePlatform() will replace it with the platform’s www_dir folder. If this value is not specified, the cwd will be used.
Returns a resolved or rejected promise depending on if the server had launched successfully.
On a fulfilled promise, the following properties are available on the returned object:
Property
Description
serve
The Node http.Server instance.
root
The requested platform’s www folder.
projectRoot
The root folder of the Cordova project.
port
The used port. requested port, the default port 8000, or incremented value of the chosen port when already in use).
launchBrowser()
Launches a browser window pointing to the specified URL.
The browser identifier to launch. Valid identifier: chrome, chromium, firefox, ie, opera, safari, edge. (Default: System Default)
dataDir
The data dir to provide to Chrome (Default:temp_chrome_user_data_dir_for_cordova)
userArgs
Additional user arguments to pass to the browser.
Return:
Returns a resolved or rejected promise depending on if the browser had launched successfully.
launchServer & servePlatform Options
The options object passed to launchServer() and servePlatform() supports the following values (all optional):
Options
Description
root
The file path on the local file system that is used as the root for the server, for default mapping of URL path to the local file system path.
port
The port for the server. Note that if this port is already in use, it will be incremented until a free port is found.
router
An ExpressJS router. If provided, this will be attached before default static handling.
noLogOutput
If true, all log output will be turned off.
noServerInfo
If true, the Static file server running on... message will not be outputed.
events
An EventEmitter to use for logging. If provided, logging will be output using events.emit('log', msg). If not provided, console.log() will be used. Note that nothing will be output in either case if noLogOutput is true.
cordova-serve
This module provides a JavaScript API to serve up a Cordova application in the browser.
API Example:
API Methods
launchServer()Launches a local HTTP server.
Code Example:
Parameters:
Return:
Returns a resolved or rejected promise depending on if the server had launched successfully.
On a fulfilled promise, the following properties are available on the returned object:
servehttp.Serverinstance.rootrootthat was specified, orcwdif none specified.port8000, or the incremented value of the chosen port when the chosen port is already in use).servePlatform()Launches a server that serves up any Cordova platform (e.g.
browser,android, etc) from the current project.Code Example:
Parameters:
Return:
Note that for
servePlatform(), therootvalue should be a Cordova project’s root folder or any folder within it.servePlatform()will replace it with the platform’swww_dirfolder. If this value is not specified, the cwd will be used.Returns a resolved or rejected promise depending on if the server had launched successfully.
On a fulfilled promise, the following properties are available on the returned object:
servehttp.Serverinstance.rootwwwfolder.projectRootport8000, or incremented value of the chosen port when already in use).launchBrowser()Launches a browser window pointing to the specified URL.
Code Example:
Parameters:
urltargetchrome,chromium,firefox,ie,opera,safari,edge. (Default: System Default)dataDirtemp_chrome_user_data_dir_for_cordova)userArgsReturn:
Returns a resolved or rejected promise depending on if the browser had launched successfully.
launchServer & servePlatform Options
The
optionsobject passed tolaunchServer()andservePlatform()supports the following values (all optional):rootportrouterExpressJSrouter. If provided, this will be attached before default static handling.noLogOutputnoServerInfotrue, theStatic file server running on...message will not be outputed.eventsEventEmitterto use for logging. If provided, logging will be output usingevents.emit('log', msg). If not provided,console.log()will be used. Note that nothing will be output in either case ifnoLogOutputistrue.