
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.
Conveniently write status updates to a stream.
Constantly crafting status blocks in JavaScript intervals was a pain.
npm install --save situation
Let's assume that you want to display the status of some variables every 2 seconds:
var situation = require('situation')
var obj = {cats: 1}
var dogs = 0
var s1 = situation()
.watch('Cats', 'obj.cats')
.watch('dogs')
.watch('Animals', function(){ return obj.cats + dogs})
s1.eval = eval(s1.evalString)
s1.start('2 seconds')
//simulate change in variables
setInterval(function() {
obj.cats += Math.floor((Math.random() * 5))
connections += 1
},250)
the output is then displayed every on an interval:
*****************************************
* Start Time: 2012-11-28T00:01:59.082Z *
* Run Time: 0:0:15 *
* Cats: 125 *
* dogs: 63 *
* Animals: 188 *
*****************************************
Creates a situation object. If no parameter is passed, process.stdout is the default stream.
Example:
var situation = require('situation')
var s1 = situation()
assert(s1.outStream, process.stdout) //true
Adds a variable to report the situation on. Must pass in as a string or a function. See the example.
Returns the situation object so that they can be chained.
Object that contains the variable functions. Must be used in conjunction with evalString.
Note: Any variables used, must be available in the context of the eval method called. That is, where
ever you call eval(situationObj.evalString) must have the variables in scope.
Example:
var situation = require('situation')
var s1 = situation().watch('counter')
s1.eval = eval(s1.evalString) //this must be called!!
See eval.
Instead of writing the text status block to the stream, a JSON object is written to the stream. This may be useful if writing to a TCP stream.
Example:
var situation = require('situation')
var processing = 55
var s1 = situation(myServer)
s1.shouldOutputJSON = true
/*
write to myServer TCP every 5 seconds
date:
{
"startTime": "2012-11-28T00:01:59.082Z",
"runTime": "0:0:15",
"processing": 55
}
*/
s1.start(5000)
Sets an internal interval so that the stream can be written to at a repeated rate. Can either
be a number or a string. If it's a number, it's assumed to be in milliseconds. If it's
a string, it must be compatible with ms. If no parameter is
passed the internal startTime will just be set, but no interval will run. You can then call
update() manually.
If the internal update interval is running, this will stop it. This is equivalent to calling clearInterval, i.e. it'll remove
it from the Node.js event run loop.
Force a manual write to the stream of the current variable situation.
Example:
var situation = require('situation')
var processing = 55
var s1 = situation()
s1.start()
setInterval(function() {
s1.update()
}, Math.floor(Math.random()*10000))
(MIT License)
Copyright 2012, JP Richardson jprichardson@gmail.com
FAQs
Conveniently write status updates to a stream.
We found that situation 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.