Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
A Publish/Subscribe implementation on top of PostgreSQL NOTIFY/LISTEN
npm install pg-pubsub --save
The pg
npm package has to be installed. Also – at least node 0.12 or iojs has to be used.
Simple:
var pubsubInstance = new PGPubsub('postgres://username@localhost/database');
pubsubInstance.addChannel('channelName', function (channelPayload) {
// Process the payload – if it was JSON that JSON has been parsed into an object for you
});
pubsubInstance.publish('channelName', { hello: "world" });
The above sends NOTIFY channelName, '{"hello":"world"}'
to PostgreSQL, which will trigger the above listener with the parsed JSON in channelPayload
.
More advanced variant:
var pubsubInstance = new PGPubsub('postgres://username@localhost/database');
pubsubInstance.addChannel('channelName');
// pubsubInstance is a full EventEmitter object that sends events on channel names
pubsubInstance.once('channelName', function (channelPayload) {
// Process the payload
});
PGPubsub
inherits from EventEmitter
one also add it oneself.NOTIFY channelName, '{"hello":"world"}'
query yourself using your ordinary Postgres pool, rather than relying on the single connection of this module. Returns a Promise that will become rejected or resolved depending on the success of the Postgres call.EventEmitter
Creating a PGPubsub
instance will not do much up front. It will prepare itself to start a Postgres connection once the first channel is added and then it will keep a connection open until its shut down, reconnecting it if it gets lost, so that it can constantly listen for new notifications.
npm test
or to watch, install grunt-cli
then do grunt watch
FAQs
A Publish/Subscribe implementation on top of PostgreSQL NOTIFY/LISTEN
We found that pg-pubsub 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.