Registry / testing / stubborn-server

stubborn-server

JSON →
library2.0.1jsnpmunverified

Stubborn Server is a Node.js library designed to create flexible stub servers for development and testing environments. It currently maintains a stable version, 2.0.1, and has a release cadence that addresses dependency updates, bug fixes, and feature enhancements as needed, with major breaking changes typically bundled into new major versions. Its core functionality includes serving static JSON mocks, handling dynamic requests with Express-based handlers, managing an in-memory database with namespace support, and providing mechanisms for aliasing mock responses and defining fallback routes (static files, proxying to other targets, or reusing existing mocks). A key differentiator is its integration with Express, allowing users to attach custom Express middleware and handlers directly, offering significant flexibility over purely configuration-driven mocking solutions. It's well-suited for integration testing and rapid front-end development against evolving APIs.

npm install stubborn-server
INSTALL
IMPORT
SIG · STUBBORN-SERVER
S
stubborn-server
testingjavascriptv2.0.1
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
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 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

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

stubbornServer
✓ const stubbornServer = require('stubborn-server');
✗ import stubbornServer from 'stubborn-server';
The package exposes a function as its default CommonJS export. It is not an ES module.
stub
✓ const stub = stubbornServer();
✗ const stub = require('stubborn-server');
The `require('stubborn-server')` call returns a function that must be invoked to create a server instance.
StubbornServerConfig
✓ // No direct import, configure via object or file const config = { logMode: 'all', servePort: 8059 };
Configuration is passed as an object to `stub.start()` or loaded from `stubborn.js`/`stubborn.json`. There is no direct TypeScript type export mentioned in the README.

This quickstart initializes and starts a stubborn server instance with a basic configuration, including an example of attaching a custom Express handler. It demonstrates how to define server settings, programmatically start the server, and includes comments on dynamic configuration changes and stopping the server.

const stubbornServer = require('stubborn-server'); // Define your server configuration const config = { logMode: 'all', // can be 'all', 'info', 'mock', 'warn', 'error' or 'none' namespace: '', // help switching between different scenarios pathToMocks: './mock-examples', // mock folder relative path servePort: 8059, includes: [], // List of files into the mock folder where the express app will be exposed for custom handling fallbacks: [ { url: '/*', target: `http://localhost:${process.env.FALLBACK_PORT ?? 3000}` // Example fallback to another server } ] }; // Create an instance of the stubborn server const stub = stubbornServer(); // Optional: Attach custom Express handlers directly before starting stub.app.use('/api/hello', (req, res) => { res.json({ message: 'Hello from custom handler!', method: req.method }); }); // Start the server with the defined configuration stub.start(config); console.log(`Stubborn Server started on port ${config.servePort}`); // Example of changing configuration during runtime (e.g., for different test scenarios) // setTimeout(() => { // console.log('Switching namespace to "alt"'); // stub.config.set({ // namespace: 'alt' // }); // }, 5000); // To stop the server (e.g., in a test teardown) // setTimeout(() => { // console.log('Stopping server...'); // stub.stop(); // }, 10000);
stubborn-server --version
Debug
Known issues
breakingVersion 2.0.0 introduced a hard dependency on Node.js version 10 or greater. Running on older Node.js versions will result in an error.
fix
Ensure your Node.js environment is version 10 or higher. Upgrade Node.js if necessary.
affects: >=2.0.0
breakingVersion 1.0.0 introduced significant API changes to support multiple independent server instances. Configuration is now isolated per instance, and each instance spawns its own Express server. Direct access to a global server instance is no longer possible.
fix
Refactor your code to create a new `stubbornServer()` instance for each server you intend to run and manage its configuration and lifecycle independently. The `stubbornServer()` call returns a function which must then be invoked `stub = stubbornServer();`.
affects: >=1.0.0
breakingVersion 1.0.0 also dropped support for Node.js versions older than the then-current LTS. While not explicitly specified in the release notes, this often implies strict adherence to currently maintained Node.js LTS lines.
fix
Always use a current Long Term Support (LTS) version of Node.js with stubborn-server to ensure compatibility and stability.
affects: >=1.0.0
gotchaStubborn Server primarily functions as a CommonJS module. Attempting to use ES module `import` syntax will fail at runtime unless your environment is configured for interoperability (e.g., via a transpiler or specific Node.js `--experimental-modules` flags).
fix
Use `const stubbornServer = require('stubborn-server');` for importing the library.
affects: >=1.0.0
gotchaThe `stubborn-server` package requires its main export, which is a function, to be invoked to create a server instance. Directly calling methods like `start()` on the imported module will result in a `TypeError`.
fix
Always initialize the server with `const stub = stubbornServer();` before calling methods like `stub.start()` or `stub.stop()`.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: stubbornServer.start is not a function
Attempting to call `start()` directly on the `require('stubborn-server')` return value instead of first instantiating the server.
fix
You need to invoke the imported function to get a server instance: `const stub = require('stubborn-server')();` then `stub.start();`
Error: stubborn-server requires Node.js version >=10
Running the package on a Node.js version older than 10.x, which is explicitly unsupported since v2.0.0.
fix
Upgrade your Node.js environment to version 10 or newer (e.g., use `nvm install 16` and `nvm use 16`).
SyntaxError: Unexpected token 'export' (for import { Name } from 'stubborn-server')
Using ES module `import` syntax to load a package that is published as a CommonJS module.
fix
Change your import statement to use CommonJS `require()`: `const stubbornServer = require('stubborn-server');`.
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
13 hits · last 30 days
node
12
OpenAI (training)
1
Resources
stubborn-server — npm install stubborn-server · libregistry