Skip to content

Instantly share code, notes, and snippets.

@deepal
Created October 7, 2019 18:26
Show Gist options
  • Select an option

  • Save deepal/0926cf5a1515e9ed589b55c663f4b4a8 to your computer and use it in GitHub Desktop.

Select an option

Save deepal/0926cf5a1515e9ed589b55c663f4b4a8 to your computer and use it in GitHub Desktop.
BCrypt Server with Thread Pool
const express = require('express');
const {WorkerPool} = require('./pool');
const app = express();
// Create a new worker pool to run script ./task.js
const pool = new WorkerPool('./task.js', 4);
app.get('/', (req, res) => {
const plainText = req.query.text;
pool.runWithArg(plainText, (err, enc) => {
if (err) return console.error(err);
return res.status(200).send(enc);
});
});
app.listen(8081);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment