
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
node-machine
Advanced tools
var Machine = require('node-machine');
With a callback function:
var Machine = require('node-machine');
Machine.build(require('machinepack-github/get-repo'))
.configure({
user: 'balderdashy',
repo: 'sails'
})
.exec(function (err, results){
if (err) {
// ...
}
// ...
});
With a switchback:
Machine.build(require('machinepack-github/get-repo'))
.configure({
user: 'balderdashy',
repo: 'sails'
})
.exec({
success: function (results){ /*...*/ },
error: function (err){ /*...*/ },
invalidApiKey: function (err){ /*...*/ },
// etc.
});
Machines are mostly just simple functions that always have the same usage paradigm:
function (inputs, cb) {
return cb();
}
If you define a function that way (let's say you export it from a local module called "foo.js"), you can actually use it as a machine like this:
require('node-machine').build(require('./foo'))
.configure({
// input values go here
})
.exec(function (err) {
console.log('all done.');
});
Since machine definitions are completely static, we must consider all of the various methods by which we might deserialize them and inject the runtime scope.
Machine
constructorWhen you require node-machine
, you get the global Machine
constructor:
var Machine = require('node-machine');
As with the top-level value exported from any node module, you really shouldn't make changes to this object since it would pollute the module elsewhere in the currently-running process (in other functions, other files, and even other modules!)
Machine.build()
is a static factory method which constructs callable functions.
var Machine = require('node-machine');
var foobar = Machine.build(function foobar(inputs, cb){ return cb(); });
Once you have a callable machine function, you can call it directly:
foobar({
foo: 1,
bar: 2
}, function (err, result) {
});
or just use the chainable convenience methods:
foobar.configure({
foo: 1,
bar: 2
})
.exec(function (err, result) {
});
Calling .configure()
on a machine returns a chainable intermediate object, much like a promise.
In the future, this object might eventually be a promise.
This allows for some flexibility in how the machine is called:
var thisFoobar = foobar.configure();
thisFoobar.configure({foo: 1});
thisFoobar.configure({bar: 2});
thisFoobar.exec(function (err, result){
});
Machines know how to cache their own results.
var Machine = require('node-machine');
var ls = Machine.build(require('machinepack-fs/ls'));
ls
.configure({
})
.cache(2000) // this is the ttl, 2000ms === 2 seconds
.exec(console.log)
/**
* Module dependencies
*/
var Machine = require('node-machine');
var M = {};
M.ls = Machine.build(require('machinepack-fs/ls'));
M.cp = Machine.build(require('machinepack-fs/cp'));
M.ls({
dir: './'
})
.exec(function (err, result) {
// and so on...
});
FAQs
Please `npm install machine` instead.
The npm package node-machine receives a total of 153 weekly downloads. As such, node-machine popularity was classified as not popular.
We found that node-machine demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.