# cordova-serve

> Apache Cordova server support for cordova-lib and cordova-browser.

Latest version **4.0.1** (published 2023-02-01) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install cordova-serve
pnpm add cordova-serve
yarn add cordova-serve
bun add cordova-serve
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: no vulnerabilities; high maintenance score.

Warnings: low downloads; no types; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 4.0.1 |
| Published | 2023-02-01 |
| First published | 2015-05-24 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 10 |
| Dependencies | 5 |
| Unpacked size | 47.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 21 |
| Author | Apache Software Foundation |
| Maintainers | brodybits, dpogue, cordovaowner, stevegill, purplecabbage, anis, filmaj, bowserj, shazron, surajpindoria, erisu, niklasmerz, janpio, normanbreau, pvpoyer, timbarham |
| Keywords | cordova, server, apache |

## Links

- npm: https://www.npmjs.com/package/cordova-serve
- Repository: https://github.com/apache/cordova-serve
- Homepage: https://github.com/apache/cordova-serve#readme
- Issues: https://github.com/apache/cordova-serve/issues
- npm.io page: https://npm.io/package/cordova-serve

## Dependencies (5)

- [open](https://npm.io/package/open.md) ^7.0.3
- [chalk](https://npm.io/package/chalk.md) ^3.0.0
- [which](https://npm.io/package/which.md) ^2.0.2
- [express](https://npm.io/package/express.md) ^4.17.1
- [compression](https://npm.io/package/compression.md) ^1.7.4

## Recent versions

- 4.0.1 (latest) — 2023-02-01
- 5.0.0-nightly.20251125002453809.sha.7518e789 (nightly) — 2025-11-25
- 1.0.1 (rc) — 2016-12-22
- 5.0.0-nightly.20251124002730161.sha.7518e789 — 2025-11-24
- 5.0.0-nightly.20251123002925587.sha.e75dcb33 — 2025-11-23
- 5.0.0-nightly.20251122002424873.sha.e75dcb33 — 2025-11-22
- 5.0.0-nightly.20251121002528744.sha.8af0e438 — 2025-11-21
- 5.0.0-nightly.20251120002524063.sha.8af0e438 — 2025-11-20
- 5.0.0-nightly.20251119002618228.sha.8af0e438 — 2025-11-19
- 5.0.0-nightly.20251118002526729.sha.e63b7901 — 2025-11-18
- 5.0.0-nightly.20251117002630731.sha.e63b7901 — 2025-11-17
- 5.0.0-nightly.20251116002746597.sha.e63b7901 — 2025-11-16
- 5.0.0-nightly.20251115002454896.sha.e63b7901 — 2025-11-15
- 5.0.0-nightly.20251114002605023.sha.e63b7901 — 2025-11-14
- 5.0.0-nightly.20251113002531212.sha.e63b7901 — 2025-11-13
- … 1467 more at https://npm.io/package/cordova-serve/versions

## README

<!--
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
#  KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
#
-->

# cordova-serve

[![NPM](https://nodei.co/npm/cordova-serve.png)](https://nodei.co/npm/cordova-serve/)

[![Node CI](https://github.com/apache/cordova-serve/workflows/Node%20CI/badge.svg?branch=master)](https://github.com/apache/cordova-serve/actions?query=branch%3Amaster)

This module provides a JavaScript API to serve up a Cordova application in the browser.

**API Example:**

```js
const cordovaServe = require('cordova-serve')();

cordovaServe.launchServer(options);
cordovaServe.servePlatform(platform, options);
cordovaServe.launchBrowser(options);
```

## API Methods

### `launchServer()`

Launches a local HTTP server.

**Code Example:**

```js
const cordovaServe = require('cordova-serve')();

cordovaServe.launchServer(options).then(function () {
    const { server, port, root } = cordovaServe;
    ...
}, error => {
    console.log(`An error occurred: ${error}`);
});
```

**Parameters:**

* **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.

**Code Example:**

```js
const cordovaServe = require('cordova-serve')();

cordovaServe.servePlatform(platform, options).then(() => {
    const { server, port, projectRoot, root } = cordovaServe;
    ...
}, error => {
    console.log(`An error occurred: ${error}`);
});
```

**Parameters:**

* **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.

**Code Example:**

```js
const cordovaServe = require('cordova-serve')();

cordovaServe.launchBrowser(options).then(
  stdout => {
    console.log(`Browser was launched successfully: ${stdout}`);
  },
  error => {
    console.log(`An error occurred: ${error}`);
  }
);
```

**Parameters:**

* **options** (optional):

Options | Description
-|-
`url` | The URL to open in the browser.
`target` | The browser identifier to launch. **Valid identifier**: `chrome`, `chromium`, `firefox`, `ie`, `opera`, `safari`. (**Default:** `chrome`.)

**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`.

---
_Source: https://npm.io/package/cordova-serve · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
