Skip to content

Instantly share code, notes, and snippets.

View Vectormike's full-sized avatar
🏠
Working from home

Victor Jonah Vectormike

🏠
Working from home
View GitHub Profile
// listen to the parent process
process.on('message', (message) => {
// send the message to the function
const response = calculatePrime(message.primeNumber);
// send the response from the function back to the parent process.
process.send(response);
// exit/shutdown the process immediately
process.exit();
});
const childProcess = fork('./calculatePrime.mjs');
childProcess.send({ primeNumber: parseInt(req.query.number) });
childProcess.on('message', (message) => res.json(message));
import { fork } from 'child_process';
// the file we want to execute
const childProcess = fork('./calculatePrime.mjs')
import express from 'express';
const app = express();
app.get('/calculateprime', (req, res) => {
const response = isPrime(parseInt(req.query.number));
return res.json(response);
});
app.listen(5000, () => console.log('Listening on 8081'));
{
"name": "prime-block",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
$ npm init -y
class Blockchain {
constructor() {
this.chain = [this.createGenesisBlock()];
}
createGenesisBlock() {
return new Block('17/102021', 'First Block');
}
appendBlock(newBlock) {
class Block {
constructor(time, data, previousHash = '') {
this.time = time;
this.data = data;
this.previousHash = previousHash;
this.hash = this.getHash()
}
getHash() {
return crypto.createHash('sha256').update(this.previousHash + this.time + JSON.stringify(this.data)).digest('hex');
remove(index) {
// check if index is out of size range
if (index < 0 || index >= this.length) {
return;
}
let current = this.head;
let previous;
let count = 0;
class LinkedList {
constructor() {
this.head = null;
this.tail = this.head;
this.length = 0;
}
append(data) {
let node = new Node(data);
if(!this.head) {