npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sync-dev-server

v1.0.3

Published

Starts a server before your tests and stops on completion. Inspired by jest-puppeteer's subpackage jest-dev-server. Setup and teardown operations are fully synchronous.

Downloads

52

Readme

Sync Dev Server

pipeline   codecov   Maintainability   Snyk Security   GitHub top language

NPM Version   install size   Depfu Dependencies   FOSSA Status   NPM License   GitHub issues

Quality Gate Status   Codacy Badge   DeepSource   codebeat badge   GitHub stars

Downloads Total   Downloads Yearly   Downloads Monthly   Downloads Weekly   Downloads Daily


Starts a server before your tests and stops on completion

Inspired by jest-puppeteer's subpackage jest-dev-server

Setup and teardown operations are fully synchronous

Try with Replit


1. Installation

npm install sync-dev-server

2. Usage

Try with Replit.

startServer(command, options);
stopServer(server, signal);

Full example, specifying all options:

// const { startServer, stopServer } = require('sync-dev-server');
import { startServer, stopServer } from 'sync-dev-server';

const options = {
  // Note: all fields below are optional with set defaults
  host: '127.0.0.1',
  port: 49152,
  timeout: 10000,
  debug: true,
  signal: 'SIGINT',
  usedPortAction: 'ignore', // alternatives are 'kill' and 'error'
  env: {
    secretKey: "bruno's fight club"
  },
}

const server = startServer('npm start', options);

// Send requests to the server or perform other operations
// ...
// ...
// ...

stopServer(server, 'SIGINT');

When using Jest, you can create and stop the server using Setup and Teardown, for example with beforeAll and afterAll. To start and stop the server for all test suites, look into setupFiles, setupFilesAfterEnv, globalSetup and globalTeardown.

2.1. startServer

2.1.1. command

Type: string

The command to start your server with. Below are a few examples:

npm start
npm run dev
yarn start
node src/app.js
ts-node src/server.ts

2.1.2. options

In src/types.ts, the options interface is defined as:

type UsedPortAction = 'error' | 'ignore' | 'kill';

interface Options {
  host?: string;
  port?: number;
  timeout?: number;
  debug?: boolean;
  signal?: string | number;
  usedPortAction?: UsedPortAction;
  env?: Record<string, string>;
}
2.1.2.1. host

Type: string, Default: undefined

Host to wait for activity before considering that the server is running.

If not specified, no address will be passed into node-netstat. This means that all local addresses will be checked, including localhost, 127.0.0.1, 0.0.0.0, etc.

2.1.2.2. port

Type: number, Default: 5000

Port to wait for activity before considering that the server is running.

2.1.2.3. timeout

Type: number, Default: 10000

The timeout for individual tasks (not total time), which are:

  1. The number of milliseconds to wait for the spawned server to be available before giving up
  2. The number of milliseconds to wait for an existing server to be killed if options.usedPortAction === 'kill'
2.1.2.4. debug

Type: boolean, Default: true

Logs the server output to stdout if true, ignore stdout otherwise.

2.1.2.5. signal

Type: number | string

Default: 'SIGTERM' (15)

The inter-process communication signals that will be used to kill any existing server, if options.usedPortAction === 'kill'.

2.1.2.6. usedPortAction

Type: 'error' | 'ignore' | 'kill'. Default: 'error'

A string that defines the action to take if the given port is already in use, whereby

  • error: Throws a generic Error object
  • ignore: Assumes that the server is already started. startServer will return null.
  • kill: the process occupying this port is automatically killed

2.1.2.7. env

Type: Record<string, string>. Default: {}

Any environment variables you want to pass into the spawned server. This will take precedence over existing variables in process.env.

2.2. stopServer

2.2.1. server

Type: ChildProcess | null

The server child process returned from startServer.

stopServer will do nothing if null is passed.

2.2.2. signal

Type: number | string. Default: 'SIGTERM' (15)

The inter-process communication signals that will be used to kill the server.

3. License

Copyright (c) 2023 Khiet Tam Nguyen

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the “Software”),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

FOSSA Status

4. Limitations

There are currently no known limitations.

5. Caveats

sync-dev-server has beentested on Linux, Windows and MacOS. It leverages node-netstat, kill-sync, dns-lookup-sync and slync which are all cross-platform.