{"id":15701021,"url":"https://github.com/jedwards1211/smart-restart","last_synced_at":"2025-07-12T13:05:41.556Z","repository":{"id":11224224,"uuid":"68825865","full_name":"jedwards1211/smart-restart","owner":"jedwards1211","description":"CommonJS module load hook that restarts or does Webpack-style hot module replacement when a file is changed","archived":false,"fork":false,"pushed_at":"2024-07-08T15:45:59.000Z","size":661,"stargazers_count":7,"open_issues_count":23,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-06T04:02:27.697Z","etag":null,"topics":["commonjs","file-watcher","file-watching","hmr","hot-module-replacement","hot-reloading","node"],"latest_commit_sha":null,"homepage":"","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/jedwards1211.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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,"zenodo":null}},"created_at":"2016-09-21T14:34:45.000Z","updated_at":"2024-07-08T15:43:53.000Z","dependencies_parsed_at":"2024-05-08T02:25:40.194Z","dependency_job_id":"0eb1cd5b-041d-47e4-ab3e-512781d58166","html_url":"https://github.com/jedwards1211/smart-restart","commit_stats":null,"previous_names":["jedwards1211/restart-hook"],"tags_count":20,"template":false,"template_full_name":null,"purl":"pkg:github/jedwards1211/smart-restart","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jedwards1211%2Fsmart-restart","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jedwards1211%2Fsmart-restart/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jedwards1211%2Fsmart-restart/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jedwards1211%2Fsmart-restart/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jedwards1211","download_url":"https://codeload.github.com/jedwards1211/smart-restart/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jedwards1211%2Fsmart-restart/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264995181,"owners_count":23694901,"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":["commonjs","file-watcher","file-watching","hmr","hot-module-replacement","hot-reloading","node"],"created_at":"2024-10-03T19:58:27.438Z","updated_at":"2025-07-12T13:05:41.503Z","avatar_url":"https://github.com/jedwards1211.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# smart-restart\n\nCommonJS module load hook that restarts or does Webpack-style hot module replacement when a file is changed\n\n[![CircleCI](https://circleci.com/gh/jedwards1211/smart-restart.svg?style=svg)](https://circleci.com/gh/jedwards1211/smart-restart)\n[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)\n[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)\n[![npm version](https://badge.fury.io/js/smart-restart.svg)](https://badge.fury.io/js/smart-restart)\n\n`nodemon` and `piping` are great, but each has their limitations:\n\n`nodemon` sometimes restarts when you change files the server isn't using, which is a hassle when you're working on\nisomorphic apps and just want a webpack hot update on the client.\n\n`piping` is difficult to use with `node-inspector` because it runs a cluster; the supervisor process gets debug port 5858,\nand your app process gets something else. It's even more of a pain to use with `--debug-brk` because the supervisor\nprocess starts with a breakpoint as well, so you have to open `node-inspector` for it, resume it, _then_ open\n`node-inspector` for your actual app.\n\nOn top of that, neither supports any hot module replacement, which is the only way to react to changes quickly in a\nlarge project.\n\n`smart-restart` combines both approaches: it uses `piping`'s require hook to only watch files that have been required,\nbut it `spawns` your app instead of running a cluster, so that you can pass `--debug` or `--debug-brk` to your app.\nAnd it provides a basic version of Webpack's hot module replacement API for Node CommonJS, without using Webpack or\ndoing any bundling.\n\n## Usage\n\nTo run `./src/index.js` in a child process and watch files it `require`s:\n\n```js\nvar launch = require('smart-restart')\n\nlaunch({\n  main: './src/index.js',         // path to your script\n  command: 'node',                // optional, the command to `spawn` (default: `process.argv[0]`)\n  commandOptions: ['--inspect'],  // optional, arguments that come before `main`\n  args: [...],                    // optional, arguments that come after `main`\n  spawnOptions: {...},            // optional, options for `spawn`\n  onChildSpawned: child =\u003e {},    // optional, callback to receive ChildProcess instance\n  ignore: /(\\/\\.|~$)/,            // optional, ignore pattern for `chokidar` (default: /(\\/\\.|~$)/)\n  usePolling: false,              // optional, whether to use polling in `chokidar` (default: false)\n  interval: 100,                  // optional, polling interval for `chokidar` (default: 100)\n  binaryInterval: 300,            // optional, binary polling interval for `chokidar` (default: 300)\n  includeModules: false,          // optional, whether to include `node_modules` (default: false)\n  killSignal: 'SIGTERM',          // optional, signal to kill process with when restarting\n  killTimeout: 5000,              // optional, max amount of milliseconds to wait for process to get killed (default: 10000)\n  deleteRequireCache: [           // optional, when any files in this array (or files they require)\n                                  //    are changed, all of these files will be deleted from `require.cache`\n                                  //    instead of restarting the process.\n    'src/server/ssr/serverSideRender.js',\n  ],\n  restartOnError: true,           // optional, restart when child process has an uncaught error/promise rejection (default: true)\n  restartOnExit: true,            // optional, restart when child process exits (default: true)\n})\n```\n\nYou can `launch` as many other processes as you want in the same supervisor process.\n\n## Hot Module Replacement\n\n`smart-restart` supports the following subset of Webpack's hot module replacement API:\n\n```js\nif (module.hot) {\n  module.hot.accept('./myModule', () =\u003e {\n    const newVersion = require('./myModule')\n    // do something with newVersion\n  })\n}\n```\n\nWebpack's other overloads for `module.hot.accept` aren't supported.\n\nIf not all ancestors of a changed module have `module.hot.accept` hooks, then `smart-restart` will\nrelaunch the whole process.\n\n## Exiting for good\n\nYou can `process.send({exit: \u003ccode\u003e})` to tell `smart-restart` to exit\nimmediately instead of waiting to relaunch your process.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjedwards1211%2Fsmart-restart","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjedwards1211%2Fsmart-restart","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjedwards1211%2Fsmart-restart/lists"}