July 19th, 2017
In Technology
No Comments
If you enjoy this article, see the other most popular articles
If you enjoy this article, see the other most popular articles
If you enjoy this article, see the other most popular articles
No one should ever use NodeJS, part MMCVXII
(written by lawrence krubner, however indented passages are often quotes). You can contact lawrence at: lawrence@krubner.com, or follow me on Twitter.
I previously wrote about a very surprising bug I discovered in NodeJS/HapiJS.
But today I face a new issue: How to parallelize work in NodeJs? I discovered this fantastic library called paralleljs. It assigns work to child processes. Fantastic idea, very similar to Python. And how do I get required libs into the child process? That is very difficult. From the issues on Github:
to make things a bit more concrete, this snippet would be representative of what I want to acheive
var myLocalExports = require('../myLocalExports.js'); var _ = require('lodash'); function myDataManipulationFunction(data) { var intermediateValue = myLocalExports.sweetFunction(data); var otherValue = _.zip(intermediateValue, [1,2,3]) return otherValue; } var p = new Parallel(myDataArray, {env: myEnvVars}) .require(__dirName + '../myLocalExports.js') .require(__dirName + '../node_modules/lodash/lodash.js') p.map(myDataManipulationFunction) // throws error, "myLocalExports" is not definedWhich… kinda makes sense. Even if the exports from myLocalExports made it into the scope of the worker…. where exactly did I define the variable “myLocalExports”
That code example is contrived, but hopefully my question is clear. What should I be doing to require in exported modules in node? And how could I assign those modules to a variable?
Post external references
- 1
https://github.com/parallel-js/parallel.js/issues/160
February 8, 2022 9:33 am
From Michael S on How I recovered from Lyme Disease: I fasted for two weeks, no food, just water
"Did you have Bartonella, too? Seems it uses autogenesis..."