{"id":20514093,"url":"https://github.com/webreflection/node-worker","last_synced_at":"2025-04-14T00:05:38.382Z","repository":{"id":65993229,"uuid":"99047380","full_name":"WebReflection/node-worker","owner":"WebReflection","description":"Web Worker like API to drive NodeJS files","archived":false,"fork":false,"pushed_at":"2023-07-04T16:38:55.000Z","size":26,"stargazers_count":33,"open_issues_count":0,"forks_count":6,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-12-31T15:13:51.125Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/WebReflection.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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}},"created_at":"2017-08-01T22:12:56.000Z","updated_at":"2024-11-26T21:46:21.000Z","dependencies_parsed_at":null,"dependency_job_id":"4bbf1bd4-64b8-4141-a59a-d79e30d86ae0","html_url":"https://github.com/WebReflection/node-worker","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2Fnode-worker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2Fnode-worker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2Fnode-worker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2Fnode-worker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WebReflection","download_url":"https://codeload.github.com/WebReflection/node-worker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232797486,"owners_count":18577981,"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-15T21:14:42.928Z","updated_at":"2025-01-06T23:08:50.539Z","avatar_url":"https://github.com/WebReflection.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# node-worker: DEPRECATED thanks to [coincident]([https://github.com/WebReflection/workway#workway--](https://github.com/WebReflection/coincident#coincidentserver)) 🎉\n\n[![License: ISC](https://img.shields.io/badge/License-ISC-yellow.svg)](https://opensource.org/licenses/ISC) [![donate](https://img.shields.io/badge/$-donate-ff69b4.svg?maxAge=2592000\u0026style=flat)](https://github.com/WebReflection/donate)\n\nWeb Worker like API to drive NodeJS files\n\n`npm install @webreflection/node-worker`\n\n### Concept\n\nThe aim of this project is to provide an alternative to [Electron](https://electron.atom.io/) environment.\nThis might be particularly useful in those platforms with constrains such Raspberry Pi Zero or 1.\n\nThe module is based on the standard [Web Worker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers) API.\n\nYou can `postMessage(data)` and receive `onmessage = (data) =\u003e {}` on both client and server.\n\nAll workers files must be inside a `workers` directory within the application folder.\n\nEvery worker is a [sandboxed VM](https://nodejs.org/api/vm.html) and it runs on the backend: nothing is shared directly with the browser.\n\n### Basic Example\n\n**NodeJS**\n```js\nvar index = require('fs').readFileSync(__dirname + '/index.html');\n\nvar http = require('http').createServer(handler);\nvar nodeWorker = require('@webreflection/node-worker');\n\nvar app = nodeWorker(http);\napp.listen(process.env.PORT);\n\nfunction handler(req, res) {\n  res.writeHead(200, 'OK', {\n    'Content-Type': 'text/html'\n  });\n  res.end(index);\n}\n```\n\n**Express**\n```js\nvar index = require('fs').readFileSync(__dirname + '/index.html');\n\nvar express = require('express');\nvar nodeWorker = require('@webreflection/node-worker');\n\nvar app = nodeWorker(express());\napp.get('/', handler);\napp.listen(process.env.PORT);\n\nfunction handler(req, res) {\n  res.writeHead(200, 'OK', {\n    'Content-Type': 'text/html'\n  });\n  res.end(index);\n}\n```\n\n**Demo index.html**\n```html\n\u003c!doctype html\u003e\n\u003c!-- socket.io must be available before /node-worker.js --\u003e\n\u003cscript src=\"/socket.io/socket.io.js\"\u003e\u003c/script\u003e\n\u003cscript src=\"/node-worker.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\nvar nw = new NodeWorker('echo.js');\nnw.postMessage({hello: \"world\"});\nnw.onmessage = function (event) {\n  console.log(event);\n};\nnw.onerror = function (error) {\n  console.error(error);\n};\n\u003c/script\u003e\n```\n\n**workers/echo.js**\n```js\n// simple echo\n// when some data arrives\n// same data goes back\nonmessage = function (e) {\n  postMessage(e.data);\n};\n```\n\nYou can clone and run `npm test` after an `npm install`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebreflection%2Fnode-worker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebreflection%2Fnode-worker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebreflection%2Fnode-worker/lists"}