Registry / devops / cordova-serve

cordova-serve

JSON →
library4.0.1jsnpmunverified

Cordova Serve is an official Apache Cordova project providing local web server capabilities essential for developing and testing Cordova applications. It integrates deeply with `cordova-lib` and `cordova-browser` to serve web assets, facilitating development workflows such as live reloading and opening the application in a browser. The current stable version is 4.0.1, with releases typically occurring as needed to address bugs, introduce new features, or update dependencies within the broader Cordova ecosystem. Its primary differentiator is its tight integration with the Cordova CLI and project structure, offering a streamlined local development experience for hybrid applications.

npm install cordova-serve
INSTALL
IMPORT
SIG · CORDOVA-SERVE
C
cordova-serve
devopsjavascriptv4.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

serve
import { serve } from 'cordova-serve';
const serve = require('cordova-serve');
The primary function exported for starting the server. CommonJS users should use destructuring.
ServeOptions
import { ServeOptions } from 'cordova-serve';
Type definition for the server configuration options, useful in TypeScript projects.
default
import serve from 'cordova-serve';
import { serve } from 'cordova-serve';
While named `serve` is common, it might also be exported as a default. Check library's specific export style if issues arise.

Demonstrates how to import and start the `cordova-serve` server with common options like port, root directory, and live reload.

import { serve } from 'cordova-serve'; import * as path from 'path'; const projectRoot = path.resolve(__dirname, 'test_app'); const wwwDir = path.join(projectRoot, 'www'); const options = { port: 8000, root: wwwDir, browser: 'default', // 'none' or 'safari', 'chrome', etc. livereload: true, // Enable live reload functionality consolelog: true, // Enable console log forwarding verbose: true // Enable verbose logging }; async function startServer() { try { console.log(`Starting Cordova server for '${wwwDir}' on port ${options.port}...`); const server = await serve(options); console.log(`Server running at http://localhost:${server.port}`); console.log('Press Ctrl+C to stop the server.'); // In a real application, you might want to add a way to stop the server // For this example, it will run until the process is terminated. } catch (error) { console.error('Failed to start Cordova server:', error); process.exit(1); } } startServer();
cordova --version
Debug
Known issues
breakingStarting with version 2.0.0, the internal API of `cordova-serve` was converted to use native JavaScript Promises, completely removing the dependency on the `q` library. Any custom extensions or direct interactions with the internal asynchronous operations of `cordova-serve` from prior versions will require significant refactoring.
fix
Update any custom code interacting with `cordova-serve`'s asynchronous functions to use standard Promise-based syntax (e.g., `async/await` or `.then().catch()`).
affects: >=2.0.0
breakingAs of `cordova-serve` version 4.0.1 (and potentially earlier versions like 2.0.0), the package explicitly requires Node.js version 10 or higher. Running with older Node.js versions will result in errors.
fix
Ensure your development environment uses Node.js version 10 or newer. Consider using a Node Version Manager (NVM) to easily switch between Node.js versions.
affects: >=2.0.0
gotchaVersion 2.0.0 introduced a change where `cordova-serve` will use the default system browser if no specific browser is provided in the configuration. This might open an unexpected browser tab if you previously relied on no browser being opened by default.
fix
To prevent a browser from opening automatically, explicitly set the `browser` option to `'none'` when invoking the serve function.
affects: >=2.0.0
gotchaVersion 2.0.1 replaced the deprecated `open` module with `opn` for opening URLs in a browser. While this is an internal fix, older versions of `cordova-serve` relying on the `open` module might encounter issues if `open` becomes entirely unmaintained or incompatible with newer Node.js versions.
fix
Upgrade to `cordova-serve` version 2.0.1 or higher to benefit from the `opn` module and avoid potential issues with the deprecated `open` dependency.
affects: <2.0.1
Errors
Common errors & fixes
Error: Cannot find module 'cordova-serve'
The `cordova-serve` package is not installed in the current project or globally.
fix
Run `npm install cordova-serve` in your project directory or `npm install -g cordova-serve` for global usage.
EADDRINUSE: address already in use :::8000
The specified port (e.g., 8000) is already being used by another process on your system.
fix
Either stop the process currently using the port, or configure `cordova-serve` to use a different port via the `port` option (e.g., `port: 8080`).
Error: Node.js version X.Y.Z is not supported. Please use Node.js >= 10.0.0.
Your current Node.js version does not meet the minimum requirement of `cordova-serve`.
fix
Update your Node.js installation to version 10 or higher. Tools like NVM (Node Version Manager) can help manage multiple Node.js versions.
Upgrade
Version history
4.0.1latest on npm
Audit
Dependencies
cordova-librequiredProvides core Cordova functionality and is the primary consumer of cordova-serve.
cordova-browserrequiredProvides browser platform support, often used in conjunction with cordova-serve for testing.
Agent activity
2 hits · last 30 days
node
2
Resources
cordova-serve — npm install cordova-serve · libregistry