{"id":21521086,"url":"https://github.com/weisjohn/sleepyhollow-node","last_synced_at":"2025-04-09T22:21:55.558Z","repository":{"id":17273119,"uuid":"20042949","full_name":"weisjohn/sleepyhollow-node","owner":"weisjohn","description":"Node.js binder for two-way communication with PhantomJS.","archived":false,"fork":false,"pushed_at":"2015-02-18T07:36:41.000Z","size":261,"stargazers_count":10,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T00:15:16.353Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/weisjohn.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}},"created_at":"2014-05-22T01:07:35.000Z","updated_at":"2024-06-22T02:57:47.000Z","dependencies_parsed_at":"2022-09-26T21:21:16.794Z","dependency_job_id":null,"html_url":"https://github.com/weisjohn/sleepyhollow-node","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weisjohn%2Fsleepyhollow-node","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weisjohn%2Fsleepyhollow-node/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weisjohn%2Fsleepyhollow-node/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weisjohn%2Fsleepyhollow-node/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/weisjohn","download_url":"https://codeload.github.com/weisjohn/sleepyhollow-node/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247694876,"owners_count":20980733,"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":[],"created_at":"2024-11-24T01:05:43.830Z","updated_at":"2025-04-09T22:21:55.528Z","avatar_url":"https://github.com/weisjohn.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"sleepyhollow-node\n==========\n\nNode.js binder for two-way communication with PhantomJS. An IPC library in two modules, used in conjunction with [sleepyhollow-phantom](https://github.com/weisjohn/sleepyhollow-phantom), via `stdin` and `stderr`. No `socket.io` or server-page hacks required. Sleepyhollow supports sending and receiving any [JSON serialzable data](http://www.json.org/) type.\n\n### usage\n\nTo send and receive messages from Node.js to PhantomJS, require and invoke `sleepyhollow-node`. This returns an `EventEmitter` instance, which allows you to implement your own message passing system. It supports both event names as well as \n\n```\nvar sleepyhollow = require('sleepyhollow-node');\nvar drjekyll = sleepyhollow('./node_modules/sleepyhollow-phantom/examples/simple.js');\n\ndrjekyll.emit('render', \"http://example.com/\");\ndrjekyll.on('rendered', function() {\n    console.log('a page was rendered');\n    drjekyll.emit('end');\n});\n```\n\n#### sleepyhollow([...options], path)\n\nArguments:\n\n1. options: Array: optional [advanced options](http://phantomjs.org/api/command-line.html) to be passed to PhantomJS.\n2. path: String: the path to your PhantomJS code to run (using sleepyhollow-phantom)\n\n[See the usage example for the corresponding PhantomJS code](https://github.com/weisjohn/sleepyhollow-phantom#usage).\n\nExample:\n\n```javascript\nvar drjekyll = sleepyhollow('--ignore-ssl-errors=true', 'myscript.js');\n```\n\n#### emit(event, [param])\n\nArguments:\n\n1. event - String: name of the event\n2. param - Mixed: optional, any `JSON.stringify()`-able value is supported\n\nReturns: null\n\nExample:\n\n```javascript\ndrjekyll.emit(\"fetch\", url);\n```\n\n\n#### on(event, listener)\n\nArguments:\n\n1. event - String: name of the event\n2. listener - Function(Mixed): receives a optional `JSON.stringify()`-able value\n\nExample:\n\n```javascript\ndrjekyll.on('payload', function(obj) {\n    console.log(obj.prop);\n})\n```\n\n\n### errors\n\nThe error support in PhantomJS isn't the best. `sleepyhollow` provides one custom event to listen for errors in your script:\n\n```\nvar sleepyhollow = require('sleepyhollow-node');\nvar drjekyll = sleepyhollow('some-phantom-script.js');\ndrjekyll.on('error', function(data) {\n    console.log(data);\n});\n```\n\nAnything that comes across `stdout` will be passed over to the `error` event handler, so if you `console.log` in your PhantomJS code, it will be sent to that handler.\n\n\n### exit\n\nIf the child `phantomjs` process exits, an `exit` event is emitted.\n\n```javascript\ndrjekyll.on('exit', function() {\n    console.log(\"phantom exited\");\n    process.exit();\n});\n```\n\nIf your Node process is exiting, sleepyhollow sends a `SIGINT` to tear down the phantomjs side.\n\n\n### examples\n\nSee the [examples](examples) folder, these can be run with `node`.\n\n\n### testing\n\n```\n$ npm test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweisjohn%2Fsleepyhollow-node","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fweisjohn%2Fsleepyhollow-node","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweisjohn%2Fsleepyhollow-node/lists"}