
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
a multi-agent system for Node
For now this is mostly wrapper around Node Cluster, with some syntactic sugar
(Illustration example - code not tested)
{Petri, common} = require 'petri'
{every, pick, pretty} = common
log = console.log
Petri ->
log "Initializing"
# start 2 processes
for _ in [0...2]
# module can be either a module name, or a module instance
# module = require './my/program'
module = './my/program'
log "spawning agent.."
worker = @spawn module, hello: 'world'
worker.on 'exit', -> log "agent died"
@on 'data', (reply, agent, msg) ->
switch msg.cmd
when 'log'
log pretty msg.msg
when 'hello'
log "agent #{agent.id} said hello: " + pretty msg.msg
else
log "unknow cmd: " + pretty msg
# send a command to all agents, every 5 seconds
every 5.sec => @broadcast cmd: "foobar", data: "foo": "bar"
module.exports = (opts) ->
{failure, warn, success, info, debug} = @logger
{pretty} = require('petri').common
# these will appear in colors in the terminal
info "hello, I do nothing"
debug "got some options: " + pretty opts
warn "woops something gone wrong"
# emit a message, will be received by the master
@emit cmd: "hello", foo: "bar"
failure "what the heck?!"
# kill the agent
process.exit -1
This function execute a block of code after T time units.
Has to be used together with a magic Number, like this:
after 5.min ->
console.log "game over"
This function execute a block of code every T time units.
Has to be used together with a magic Number, like this:
every 3.sec ->
console.log "checkpoint!"
Here is the list of supported magic time units:
Tell me if you need more pre-built units
This function generate a unique random id. Warning:: it sucks. You should probably use node-uuid instead. But this is enough for basic debug cases
Copy an object, using a JSON dump then parse. This is not efficient, I will try to remplace it with node-v8-clone, which is more efficient
Probability of something. Examole:
It does not return true or false, but 1 or 0, so you can use it to do fuzzy (probabilistic) programming, with inference rules and other things like that. Have fun.
Usage:
if P 0.5
console.log "A"
else
console.log "B"
Stolen from underscore.js. Check if something is a Function
Stolen from underscore.js. Check if something is undefined
Stolen from underscore.js. Check if something is a true Array (eg. a String will return false)
Stolen from underscore.js. Check if something is a String
Stolen from underscore.js. Check if something is a Number
Stolen from underscore.js. Check if something is a Boolean
Random integer between min and max. Integer means: rounded.
Helper function to round a number to 2 decimals
Helper function to round a number to 3 decimals (yeah..)
Compute the sha1 synchronously. Be warned.
A constant indicating the number of core you can use to spawn workers. This function has an heuristic to save CPU by not counting the base core, see below.
Implementation:
cpus = Math.round(os.cpus().length)
if (cpus < 3) then 1 else (cpus - 2)
Stolen from node-deck. This function picks a random item from a weighted index, see example:
store =
key1: 50
key2: 200
key3: 10
key = pick store
# most of the time, key2 will be extracted, sometimes key1, rarely key3
Prettify an object to make it human-readable. Equavalent to "inspect(obj, false, 20, true).toString()""
Read the content of a file synchronously. Useful for simple command line script, than don't need to be async.
equivalent to: "fs.readFileSync(file_path, 'utf8')"
FAQs
petri
We found that petri demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.