
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
node-machine
Advanced tools
First, here's a quick example:
$ node
> require('machinepack-github').getRepo
-----------------------------------------
[Machine: get-repo]
Fetch metadata about a github repo.
Inputs:
• repo (type: string)
• user (type: string)
-----------------------------------------
> require('machinepack-github').getRepo({repo: 'sails', user: 'balderdashy'}).exec(console.log)
{ ... }
Github.getRepo({
user: 'balderdashy',
repo: 'sails'
}, function (err, repo) { /* ... */ });
Github.getRepo({
user: 'balderdashy',
repo: 'sails'
})
.exec({
success: function (repo){ /*...*/ },
error: function (err){ /*...*/ },
invalidApiKey: function (err){ /*...*/ },
// etc.
});
Github.getRepo({
user: 'balderdashy',
repo: 'sails'
})
.setEnvironment({
config: sails.config.githubCredentials
})
.exec(function (err, repo) {
// ...
});
##### Low-level usage:
> (machinepack-independent)
```javascript
var Machine = require('node-machine');
Machine.build(require('machinepack-github/get-repo'))
.configure({
user: 'balderdashy',
repo: 'sails'
}).exec(function (err, results){
if (err) {
// ...
}
// ...
})
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 stateless Machine
constructor:
var Machine = require('node-machine');
console.log(Machine);
/*
-----------------------------------------
node-machine
v0.2.2
• License : MIT
• Docs : http://node-machine.org
-----------------------------------------
*/
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({ttl: 2000}) // this is the ttl, 2000ms === 2 seconds
.exec(console.log)
FAQs
Please `npm install machine` instead.
The npm package node-machine receives a total of 180 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
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.