# node-worker
**Repository Path**: mirrors_WebReflection/node-worker
## Basic Information
- **Project Name**: node-worker
- **Description**: Web Worker like API to drive NodeJS files
- **Primary Language**: Unknown
- **License**: ISC
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2020-08-19
- **Last Updated**: 2026-05-23
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# node-worker: DEPRECATED thanks to [coincident]([https://github.com/WebReflection/workway#workway--](https://github.com/WebReflection/coincident#coincidentserver)) 🎉
[](https://opensource.org/licenses/ISC) [](https://github.com/WebReflection/donate)
Web Worker like API to drive NodeJS files
`npm install @webreflection/node-worker`
### Concept
The aim of this project is to provide an alternative to [Electron](https://electron.atom.io/) environment.
This might be particularly useful in those platforms with constrains such Raspberry Pi Zero or 1.
The module is based on the standard [Web Worker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers) API.
You can `postMessage(data)` and receive `onmessage = (data) => {}` on both client and server.
All workers files must be inside a `workers` directory within the application folder.
Every worker is a [sandboxed VM](https://nodejs.org/api/vm.html) and it runs on the backend: nothing is shared directly with the browser.
### Basic Example
**NodeJS**
```js
var index = require('fs').readFileSync(__dirname + '/index.html');
var http = require('http').createServer(handler);
var nodeWorker = require('@webreflection/node-worker');
var app = nodeWorker(http);
app.listen(process.env.PORT);
function handler(req, res) {
res.writeHead(200, 'OK', {
'Content-Type': 'text/html'
});
res.end(index);
}
```
**Express**
```js
var index = require('fs').readFileSync(__dirname + '/index.html');
var express = require('express');
var nodeWorker = require('@webreflection/node-worker');
var app = nodeWorker(express());
app.get('/', handler);
app.listen(process.env.PORT);
function handler(req, res) {
res.writeHead(200, 'OK', {
'Content-Type': 'text/html'
});
res.end(index);
}
```
**Demo index.html**
```html
```
**workers/echo.js**
```js
// simple echo
// when some data arrives
// same data goes back
onmessage = function (e) {
postMessage(e.data);
};
```
You can clone and run `npm test` after an `npm install`.