{"id":15374637,"url":"https://github.com/nktnet1/sync-dev-server","last_synced_at":"2025-04-15T15:11:37.789Z","repository":{"id":204079731,"uuid":"710824241","full_name":"nktnet1/sync-dev-server","owner":"nktnet1","description":"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","archived":false,"fork":false,"pushed_at":"2024-09-30T21:57:18.000Z","size":738,"stargazers_count":1,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-17T16:22:04.765Z","etag":null,"topics":["automatic","development","http","jest","jest-dev-server","localhost","nodejs","server","start","sync","synchronous"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/sync-dev-server","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nktnet1.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-27T14:09:37.000Z","updated_at":"2024-09-14T08:19:26.000Z","dependencies_parsed_at":"2024-10-21T20:20:40.459Z","dependency_job_id":null,"html_url":"https://github.com/nktnet1/sync-dev-server","commit_stats":{"total_commits":123,"total_committers":4,"mean_commits":30.75,"dds":0.1382113821138211,"last_synced_commit":"a90448c53908d38eb144628a5ce3759f41200d51"},"previous_names":["nktnet1/sync-dev-server"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nktnet1%2Fsync-dev-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nktnet1%2Fsync-dev-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nktnet1%2Fsync-dev-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nktnet1%2Fsync-dev-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nktnet1","download_url":"https://codeload.github.com/nktnet1/sync-dev-server/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249094932,"owners_count":21211837,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automatic","development","http","jest","jest-dev-server","localhost","nodejs","server","start","sync","synchronous"],"created_at":"2024-10-01T13:59:13.946Z","updated_at":"2025-04-15T15:11:37.762Z","avatar_url":"https://github.com/nktnet1.png","language":"TypeScript","readme":"\u003cdiv align=\"center\"\u003e\n\n# [![Sync Dev Server](logo.svg)](https://github.com/nktnet1/sync-dev-server)\n\n[![pipeline](https://github.com/nktnet1/sync-dev-server/actions/workflows/pipeline.yml/badge.svg)](https://github.com/nktnet1/sync-dev-server/actions/workflows/pipeline.yml)\n\u0026nbsp;\n[![codecov](https://codecov.io/gh/nktnet1/sync-dev-server/branch/main/graph/badge.svg?token=RAC7SKJTGU)](https://codecov.io/gh/nktnet1/sync-dev-server)\n\u0026nbsp;\n[![Maintainability](https://api.codeclimate.com/v1/badges/a2c33076b9a9ac34bf7e/maintainability)](https://codeclimate.com/github/nktnet1/sync-dev-server/maintainability)\n\u0026nbsp;\n[![Snyk Security](https://snyk.io/test/github/nktnet1/sync-dev-server/badge.svg)](https://snyk.io/test/github/nktnet1/sync-dev-server)\n\u0026nbsp;\n[![GitHub top language](https://img.shields.io/github/languages/top/nktnet1/sync-dev-server)](https://github.com/search?q=repo%3Anktnet1%2Fsync-dev-server++language%3ATypeScript\u0026type=code)\n\n[![NPM Version](https://img.shields.io/npm/v/sync-dev-server?logo=npm)](https://www.npmjs.com/package/sync-dev-server?activeTab=versions)\n\u0026nbsp;\n[![install size](https://packagephobia.com/badge?p=sync-dev-server)](https://packagephobia.com/result?p=sync-dev-server)\n\u0026nbsp;\n[![Depfu Dependencies](https://badges.depfu.com/badges/6c4074c4d23ad57ee2bfd9ff90456090/overview.svg)](https://depfu.com/github/nktnet1/sync-dev-server?project_id=39032)\n\u0026nbsp;\n[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fnktnet1%2Fsync-dev-server.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fnktnet1%2Fsync-dev-server?ref=badge_shield)\n\u0026nbsp;\n[![NPM License](https://img.shields.io/npm/l/sync-dev-server)](https://opensource.org/license/mit/)\n\u0026nbsp;\n[![GitHub issues](https://img.shields.io/github/issues/nktnet1/sync-dev-server.svg?style=social)](https://github.com/nktnet1/sync-dev-server/issues)\n\n[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=nktnet1_sync-dev-server\u0026metric=alert_status)](https://sonarcloud.io/summary/new_code?id=nktnet1_sync-dev-server)\n\u0026nbsp;\n[![Codacy Badge](https://app.codacy.com/project/badge/Grade/945ede979ccc49d98ecec19e41bb75b9)](https://app.codacy.com/gh/nktnet1/sync-dev-server/dashboard?utm_source=gh\u0026utm_medium=referral\u0026utm_content=\u0026utm_campaign=Badge_grade)\n\u0026nbsp;\n[![DeepSource](https://app.deepsource.com/gh/nktnet1/sync-dev-server.svg/?label=active+issues\u0026show_trend=true\u0026token=r1frerF1-N2Mhrc7ZXIC1uNa)](https://app.deepsource.com/gh/nktnet1/sync-dev-server/)\n\u0026nbsp;\n[![codebeat badge](https://codebeat.co/badges/c6822dde-202e-43c7-a6cc-cd46ce7f5c41)](https://codebeat.co/projects/github-com-nktnet1-sync-dev-server-main)\n\u0026nbsp;\n[![GitHub stars](https://img.shields.io/github/stars/nktnet1/sync-dev-server.svg?style=social)](https://github.com/nktnet1/sync-dev-server/stargazers)\n\n[![Downloads Total](https://badgen.net/npm/dt/sync-dev-server)](https://moiva.io/?npm=sync-dev-server)\n\u0026nbsp;\n[![Downloads Yearly](https://badgen.net/npm/dy/sync-dev-server)](https://moiva.io/?npm=sync-dev-server)\n\u0026nbsp;\n[![Downloads Monthly](https://badgen.net/npm/dm/sync-dev-server)](https://moiva.io/?npm=sync-dev-server)\n\u0026nbsp;\n[![Downloads Weekly](https://badgen.net/npm/dw/sync-dev-server)](https://moiva.io/?npm=sync-dev-server)\n\u0026nbsp;\n[![Downloads Daily](https://badgen.net/npm/dd/sync-dev-server)](https://moiva.io/?npm=sync-dev-server)\n\n---\n\nStarts a server before your tests and stops on completion\n\nInspired by [jest-puppeteer](https://github.com/argos-ci/jest-puppeteer)'s subpackage [jest-dev-server](https://github.com/argos-ci/jest-puppeteer/tree/main/packages/jest-dev-server#readme)\n\nSetup and teardown operations are fully synchronous\n\n[![Try with Replit](https://replit.com/badge?caption=Try%20with%20Replit)](https://replit.com/@nktnet1/sync-dev-server-example#index.js)\n\n\u003c/div\u003e\n\n---\n\n- [1. Installation](#1-installation)\n- [2. Usage](#2-usage)\n    - [2.1. startServer](#21-startserver)\n        - [2.1.1. command](#211-command)\n        - [2.1.2. options](#212-options)\n            - [2.1.2.1. host](#2121-host)\n            - [2.1.2.2. port](#2122-port)\n            - [2.1.2.3. timeout](#2123-timeout)\n            - [2.1.2.4. debug](#2124-debug)\n            - [2.1.2.5. signal](#2125-signal)\n            - [2.1.2.5. usedPortAction](#2126-usedportaction)\n            - [2.1.2.5. env](#2127-env)\n    - [2.2. stopServer](#22-stopserver)\n        - [2.2.1. server](#221-server)\n        - [2.2.2. signal](#222-signal)\n- [3. License](#3-license)\n- [4. Limitations](#4-limitations)\n- [5. Caveats](#5-caveats)\n\n## 1. Installation\n\n```\nnpm install sync-dev-server\n```\n\n## 2. Usage\n\nTry with [Replit](https://replit.com/@nktnet1/sync-dev-server-example#index.js).\n\n```\nstartServer(command, options);\nstopServer(server, signal);\n```\n\nFull example, specifying all options:\n\n```javascript\n// const { startServer, stopServer } = require('sync-dev-server');\nimport { startServer, stopServer } from 'sync-dev-server';\n\nconst options = {\n  // Note: all fields below are optional with set defaults\n  host: '127.0.0.1',\n  port: 49152,\n  timeout: 10000,\n  debug: true,\n  signal: 'SIGINT',\n  usedPortAction: 'ignore', // alternatives are 'kill' and 'error'\n  env: {\n    secretKey: \"bruno's fight club\"\n  },\n}\n\nconst server = startServer('npm start', options);\n\n// Send requests to the server or perform other operations\n// ...\n// ...\n// ...\n\nstopServer(server, 'SIGINT');\n```\n\nWhen using [Jest](https://jestjs.io), you can create and stop the server using [Setup and Teardown](https://jestjs.io/docs/setup-teardown), for example with [beforeAll](https://jestjs.io/docs/api#beforeallfn-timeout) and [afterAll](https://jestjs.io/docs/api#afterallfn-timeout).\nTo start and stop the server for all test suites, look into [setupFiles](https://jestjs.io/docs/configuration#setupfiles-array), [setupFilesAfterEnv](https://jestjs.io/docs/configuration#setupfilesafterenv-array), [globalSetup](https://jestjs.io/docs/configuration#globalsetup-string) and [globalTeardown](https://jestjs.io/docs/configuration#globalteardown-string).\n\n### 2.1. startServer\n\n#### 2.1.1. command\n\nType: `string`\n\nThe command to start your server with. Below are a few examples:\n```\nnpm start\nnpm run dev\nyarn start\nnode src/app.js\nts-node src/server.ts\n```\n\n#### 2.1.2. options\n\nIn [src/types.ts](src/types.ts), the options interface is defined as:\n\n```typescript\ntype UsedPortAction = 'error' | 'ignore' | 'kill';\n\ninterface Options {\n  host?: string;\n  port?: number;\n  timeout?: number;\n  debug?: boolean;\n  signal?: string | number;\n  usedPortAction?: UsedPortAction;\n  env?: Record\u003cstring, string\u003e;\n}\n```\n\n##### 2.1.2.1. host\n\nType: `string`, Default: `undefined`\n\nHost to wait for activity before considering that the server is running.\n\nIf not specified, no `address` will be passed into [node-netstat](https://github.com/danielkrainas/node-netstat). This means that all local addresses will be checked, including `localhost`, `127.0.0.1`, `0.0.0.0`, etc.\n\n##### 2.1.2.2. port\n\nType: `number`, Default: `5000`\n\nPort to wait for activity before considering that the server is running.\n\n##### 2.1.2.3. timeout\n\nType: `number`, Default: `10000`\n\nThe timeout for individual tasks (not total time), which are:\n1. The number of milliseconds to wait for the spawned server to be available before giving up\n2. The number of milliseconds to wait for an existing server to be killed if `options.usedPortAction === 'kill'`\n\n##### 2.1.2.4. debug\n\nType: `boolean`, Default: `true`\n\nLogs the server output to `stdout` if true, ignore `stdout` otherwise.\n\n##### 2.1.2.5. signal\n\nType: `number | string`\n\nDefault: `'SIGTERM'` (`15`)\n\nThe [inter-process communication signals](https://en.wikipedia.org/wiki/Signal_(IPC)) that will be used to kill any existing server, if `options.usedPortAction === 'kill'`.\n\n##### 2.1.2.6. usedPortAction\n\nType: `'error' | 'ignore' | 'kill'`. Default: `'error'`\n\nA string that defines the action to take if the given port is already in use, whereby\n- `error`: Throws a generic [Error](https://nodejs.org/api/errors.html#class-error) object\n- `ignore`: Assumes that the server is already started. `startServer` will return `null`.\n- `kill`: the process occupying this port is automatically killed\n\n#### 2.1.2.7. env\n\nType: `Record\u003cstring, string\u003e`. Default: `{}`\n\nAny environment variables you want to pass into the spawned server. This will take precedence over existing variables in `process.env`.\n\n### 2.2. stopServer\n\n#### 2.2.1. server\n\nType: [`ChildProcess`](https://nodejs.org/api/child_process.html#class-childprocess) | `null`\n\nThe server child process returned from [`startServer`](#21-startserver). \n\n`stopServer` will do nothing if `null` is passed.\n\n#### 2.2.2. signal\n\nType: `number | string`. Default: `'SIGTERM'` (`15`)\n\nThe [inter-process communication signals](https://en.wikipedia.org/wiki/Signal_(IPC)) that will be used to kill the server.\n\n## 3. License\n\n\u003cdetails closed\u003e\n\u003csummary\u003e\n  Massachusetts Institute of Technology\n  (\u003ca href=\"https://opensource.org/license/mit\" target=\"_blank\"\u003eMIT\u003c/a\u003e)\n\u003c/summary\u003e\n\n\u003cbr/\u003e\n\n```\nCopyright (c) 2023 Khiet Tam Nguyen\n\nPermission is hereby granted, free of charge, to any person obtaining a\ncopy of this software and associated documentation files (the “Software”),\nto deal in the Software without restriction, including without limitation\nthe rights to use, copy, modify, merge, publish, distribute, sublicense,\nand/or sell copies of the Software, and to permit persons to whom the\nSoftware is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\nTHE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\nFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\nDEALINGS IN THE SOFTWARE.\n```\n\n[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fnktnet1%2Fsync-dev-server.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fnktnet1%2Fsync-dev-server?ref=badge_large)\n\n\u003c/details\u003e\n\n## 4. Limitations\n\nThere are currently no known limitations.\n\n## 5. Caveats\n\n**sync-dev-server** has been tested on Linux, Windows and MacOS.\n\nIt leverages [node-netstat](https://github.com/danielkrainas/node-netstat), [kill-sync](https://github.com/nktnet1/kill-sync), [dns-lookup-sync](https://github.com/nktnet1/dns-lookup-sync) and [slync](https://github.com/nktnet1/slync) which are all cross-platform.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnktnet1%2Fsync-dev-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnktnet1%2Fsync-dev-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnktnet1%2Fsync-dev-server/lists"}