{"id":15497364,"url":"https://github.com/heapwolf/liveswap","last_synced_at":"2025-09-08T11:16:02.398Z","repository":{"id":11806919,"uuid":"14354682","full_name":"heapwolf/liveswap","owner":"heapwolf","description":"zero downtime re-deploys with Node.js","archived":false,"fork":false,"pushed_at":"2015-06-17T13:17:05.000Z","size":539,"stargazers_count":161,"open_issues_count":9,"forks_count":10,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-07-02T18:17:08.041Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/heapwolf.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-11-13T05:16:05.000Z","updated_at":"2025-01-02T01:03:35.000Z","dependencies_parsed_at":"2022-08-26T23:40:56.670Z","dependency_job_id":null,"html_url":"https://github.com/heapwolf/liveswap","commit_stats":null,"previous_names":["hij1nx/liveswap"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/heapwolf/liveswap","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heapwolf%2Fliveswap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heapwolf%2Fliveswap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heapwolf%2Fliveswap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heapwolf%2Fliveswap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/heapwolf","download_url":"https://codeload.github.com/heapwolf/liveswap/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heapwolf%2Fliveswap/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274174271,"owners_count":25235203,"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","status":"online","status_checked_at":"2025-09-08T02:00:09.813Z","response_time":121,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-10-02T08:33:11.248Z","updated_at":"2025-09-08T11:16:02.371Z","avatar_url":"https://github.com/heapwolf.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SYNOPSIS\nSafe code hotswap for zero downtime re-deploys.\n\n# BUILD STATUS\n[![Build Status](http://img.shields.io/travis/hij1nx/skipfile.svg?style=flat)](https://travis-ci.org/hij1nx/skipfile)\n\n# MOTIVATION\nAn application in production should not need to be stopped in order to\nutilize new code.\n\n# DESCRIPTION\nliveswap is a library that helps you update an application’s code without stopping it.\nIt also ships with a command-line tool and it doesn’t impose any special requirements\nor conventions on your application code.\n\nIt works by creating a light-weight master process that runs your application code as\nworker processes. It then starts listening for instructions.\n\nWhen you send an upgrade instruction, workers take turns disconnecting their underlying\nservers. When a server is disconnected, it lets the old connections finish up, but no\nnew connections are accepted. When all of the worker’s connections have been closed, it\nwill be retired and a new one will be created using the new code. For more in depth\ninformation read [`this`][0] blog post.\n\n# USAGE\n\n## Install\n```bash\nnpm install liveswap -g\n```\n\n## Example\nUsing the node.js hello world example, in a filed named `index1.js`...\n\n### First Version (Sample Code)\n```js\nvar http = require('http')\nhttp.createServer(function (req, res) {\n  res.writeHead(200, {'Content-Type': 'text/plain'})\n  res.end('Hello World\\n')\n}).listen(1337, '127.0.0.1')\nconsole.log('Server running at http://127.0.0.1:1337/')\n```\n\n### Startup\nStart the application using liveswap from the command-line...\n\n```bash\nliveswap -s index1.js\n```\nAlternatively, start liveswap programmatically...\n\n```js\nvar liveswap = require('liveswap')\nliveswap('./index1.js')\n```\n\n### Second Version (Sample Code)\nNow we have an updated version of the code in `index2.js`...\n\n```js\nvar http = require('http')\nhttp.createServer(function (req, res) {\n  res.writeHead(404, {'Content-Type': 'text/plain'})\n  res.end('Not Found\\n')\n}).listen(1337, '127.0.0.1')\nconsole.log('Server running at http://127.0.0.1:1337/')\n```\n\n### Live Update\nUpdate the current code by sending an update command to the server.\n\n```js\nliveswap -u ./index2.js\n```\n\nAfter sending an update message the worker processes will wait for\nany current connections to end before restarting with the new code.\n\n# CLI Options\n\n```bash\nOptions:\n  -p, --port     \u003cport\u003e specify the liveswap server port.                      [default: 3000]\n  -a, --address  \u003caddress\u003e specify the ip address to run on.                   [default: \"127.0.0.1\"]\n  -f, --forks    \u003cnumber\u003e specify how many worker processes to spawn           [default: 2]\n  -u, --upgrade  [\u003cpath\u003e] specify the source code to upgrade to.\n  --pre-upgrade  \u003cpath\u003e a module to handle pre upgrade logic.\n  -k, --kill     kill all forked worker processes and respawn.\n  -d, --die      kill all forked worker processes and quit master process.\n  -m, --message  \u003cmessage\u003e send a message to all the forked worker processes.\n  -s, --start    \u003cpath\u003e start a node process cluster.\n  -H, --head     \u003cpath\u003e path to HEAD file\n  -z             disable zero-downtime, upgrade will kill processes\n  -v, --version  print program version and exit\n```\n\nPre-upgrade allows you to require a module that will be executed before each\ntime the upgrade happens.\n\n```bash\nliveswap --pre-upgrade ./pull.js --start ./index1.js\n```\n\nThe pre-upgrade module should export a single function as its interface.\nHere's an example of what that module might look like:\n\n```js\nfunction preupgrade(data, callback) {\n  console.log('executing pre-upgrade script...');\n\n  var err, value = data.value;\n  try {\n    // execute pre-upgrade code\n  } catch (e) {\n    err = e.toString();\n  }\n\n  callback(err, value);\n}\nmodule.exports = preupgrade;\n```\n\n# API\n\n## liveswap(opts)\nThe main export of this library accepts an options object or a string. If a\nstring is specified, it will be interpreted as the `target` option.\n\n### [option] `{ target: \u003cString\u003e }`\n\n### [option] `{ port: \u003cNumber\u003e }`\n\n### [option] `{ address: \u003cString\u003e }`\n\n### [option] `{ forks: \u003cNumber\u003e }`\n\n### [option] `{ head: \u003cString\u003e }`\n\n### [option] `{ 'pre-upgrade': \u003cString\u003e }`\n\n### [option] `{ 'zero-downtime': \u003cBoolean\u003e }`\n\n```js\nliveswap({\n  target: './index.js',\n  port: 9008,\n  address: '0.0.0.0',\n  forks: 2,\n  head: '/tmp/HEAD',\n  'pre-upgrade': './pull.js',\n  'zero-downtime': false\n})\n```\n\n[0]:https://medium.com/node-js-javascript/f00ce09abb77\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheapwolf%2Fliveswap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fheapwolf%2Fliveswap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheapwolf%2Fliveswap/lists"}