The `with-server` package is a command-line utility and programmatic API designed to orchestrate local server startup, command execution (typically end-to-end tests), and server shutdown. It automatically handles port allocation via the `$PORT` environment variable, waits for the server to become ready, and exposes `$SERVER_URL` to the executed command. It offers options to specify the server's start script and control output redirection. The current stable version is 2.1.0, with releases appearing infrequently, driven by feature additions or critical maintenance, such as the major Node.js version bump in v2.0.0. It's a focused tool for e2e testing workflows, abstracting away the complexities of server lifecycle management during test runs, differentiating itself by its simplicity and direct integration with npm scripts.
npm install with-serverVerified import paths — ran on the pinned version, not inferred.
Demonstrates programmatic usage of `with-server` to run a test command (e.g., Cypress) against a local server, specifying the server start script and output redirection, and handling the exit code.
Upgrade your Node.js environment to version 16 or later. Check your `package.json` `engines` field and CI/CD configurations.
Ensure your server script reads from `process.env.PORT` (e.g., `app.listen(process.env.PORT || 3000)`) or, if using a fixed port, pass it via the programmatic API or environment variable before `with-server` execution.
Use the `--redirect stdout` command-line option or `redirect: 'stdout'` in the programmatic API to write server output to stdout. Alternatively, use `--redirect null` or `redirect: 'null'` to silence server output completely.
Verify your server's start script, ensure it's listening on `process.env.PORT`, and check for any startup errors in the server's output (redirect to stdout for debugging). Increase timeout if server takes long to start.
Ensure the test command is installed as a `devDependency` (e.g., `npm install cypress --save-dev`) and either run `with-server` via `npm scripts` or directly reference the local binary (e.g., `node_modules/.bin/cypress`).
Run `npm install with-server --save-dev` to install the package. If using ESM, ensure your setup correctly handles CJS module imports or consider bundling your code.
No dependency data recorded yet.