This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const {wrapAsWorker} = require('./pool'); | |
const encrypt = require('../encrypt'); | |
wrapAsWorker(encrypt); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const bcrypt = require('bcrypt'); | |
module.exports = (plainText) => { | |
const salt = bcrypt.genSaltSync(12); | |
return bcrypt.hashSync(plainText, salt); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const encrypt = require('./encrypt'); | |
const app = express(); | |
app.get('/', (req, res, next) => { | |
const enc = encrypt(req.query.text); | |
res.status(200).send(enc); | |
}); | |
app.listen(8080); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const {Worker, isMainThread, parentPort, workerData} = require('worker_threads'); | |
const encrypt = require('./encrypt'); | |
if (isMainThread) { | |
const app = express(); | |
app.get('/', (req, res, next) => { | |
console.log('serving request...'); | |
const worker = new Worker(__filename, {workerData: req.query.text}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
type: 'create', | |
tid: 'c3b88a9f-9c74-4036-8203-7ac818958335', | |
data: { | |
title: 'New user account', | |
description: 'Create a new user account for Captain America', | |
status: 'open', | |
assignee: 'shield-support' | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.createView('tickets', 'ticketevents', [ | |
{ | |
$sort: { timestamp: 1 } | |
}, | |
{ | |
$group: { | |
_id: '$tid', | |
ticketDetails: { | |
$mergeObjects: '$data' | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create a new context. | |
Local<Context> context = Context::New(isolate); | |
// Enter the context for compiling and running the hello world script. | |
Context::Scope context_scope(context); | |
// Create a string containing the JavaScript source code. | |
Local<String> source = String::NewFromUtf8(isolate, "'Hello' + ', World!'"); | |
// Compile the source code. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create a template for the global object and set the built-in global functions | |
Local<ObjectTemplate> global = ObjectTemplate::New(isolate); | |
global->Set( | |
String::NewFromUtf8(isolate, "log"), | |
FunctionTemplate::New(isolate, LogCallback) | |
); | |
// Each processor gets its own context so different processors do not affect each other | |
Persistent<Context> context = Context::New(isolate, NULL, global); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const {EventEmitter} = require('events'); | |
const emitter = new EventEmitter(); | |
emitter.on('message', (message) => { | |
console.log(`Handler 1 message: ${message}`); | |
}); | |
emitter.on('message', (message) => { | |
console.log(`Handler 2 message: ${message}`); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void Binding(const FunctionCallbackInfo<Value>& args) { | |
Environment* env = Environment::GetCurrent(args); | |
Local<String> module = args[0]->ToString(env->isolate()); | |
node::Utf8Value module_v(env->isolate(), module); | |
Local<Object> cache = env->binding_cache_object(); | |
Local<Object> exports; | |
if (cache->Has(module)) { |
NewerOlder