{"id":17054218,"url":"https://github.com/tlhunter/dumbpubsub","last_synced_at":"2025-04-12T17:01:58.264Z","repository":{"id":4496056,"uuid":"5635404","full_name":"tlhunter/dumbpubsub","owner":"tlhunter","description":"Allows non-evented apps to subscribe to Node.js events over HTTP","archived":false,"fork":false,"pushed_at":"2012-09-10T20:41:00.000Z","size":670,"stargazers_count":3,"open_issues_count":7,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-09T21:44:30.234Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/dumb","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tlhunter.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-09-01T00:07:14.000Z","updated_at":"2016-01-12T00:24:01.000Z","dependencies_parsed_at":"2022-09-20T23:21:55.568Z","dependency_job_id":null,"html_url":"https://github.com/tlhunter/dumbpubsub","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tlhunter%2Fdumbpubsub","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tlhunter%2Fdumbpubsub/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tlhunter%2Fdumbpubsub/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tlhunter%2Fdumbpubsub/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tlhunter","download_url":"https://codeload.github.com/tlhunter/dumbpubsub/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248602275,"owners_count":21131613,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-14T10:14:18.178Z","updated_at":"2025-04-12T17:01:58.240Z","avatar_url":"https://github.com/tlhunter.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"DumbPubSub\n===\n\nThis module is for Node.js applications in a heterogeneus environment, where\nyou want your non long-running-process applications (such as a PHP app) to\nbe able to subscribe to events from your Node.js application.\n\nFor example, if a client updates their email address, and you want to alert\nyour PHP application so that it can perhaps change some memcache entry it\nuses, this module is what you are looking for.\n\nExternal apps can provide an event to bind on to, and a URL to listen on.\nWhen the event occurs, the relevant data is POSTed to said URL.\n\nLong term goals for this project include saving the subscription data to either\na Redis or MongoDB database. The first iteration will only save it to a local\nJSON file. There may eventually be so many entries that keeping it in Node memory\nwouldn't work, so will have to explore that.\n\nAlso, you wouldn't want to use this for inter-nodejs-app communications, for\nthat you would want to use someone elses library.\n\nExample Requests\n===\n\n    POST /subscribe\n    P:event\n    P:url\n    Success: 201 CREATED\n    Failure: 409 CONFLICT\n\n    DELETE /subscribe\n    (P/G:event)\n    (P/G:url)\n    Success: 200 OK\n    Failure: 404 NOT FOUND\n\n    GET /subscribe\n    (G:event)\n    (G:url)\n    Success: 200 OK\n\nExample Server Code\n===\n\n    var dumb = require('dumb');\n    // npm install express\n    var express = require('express');\n\n    var app = express(); // Create an Express app\n    app.use(express.bodyParser());\n\n    dumb.attach(app) // DumbPubSub will now use the existing Express app\n        .notifyEvent() // By default, we don't tell client what was run, we assume their URL will let them know\n        .persistOnExit() // Makes sure we save all subscriptions to disk when we quit\n        .restore('subscriptions.json') // Reads this file for subscription info\n        .setUrl('/subscribe') // Sets the URL which we listen on\n        .enable(); // Tells the express app that we want to listen on some URLs\n\n    // Normal application requests work as expected\n    app.get('/', function(req, res) {\n        res.send('hello world');\n    });\n\n    // Allows us to trigger an event using a browser, for testing purposes\n    app.get('/trigger/:event', function(req, res) {\n        dumb.emit(req.route.params.event, {\n            from: 'web'\n        });\n        res.send(200);\n    });\n\n    app.listen(3000); // Express (and DumbPubSub) both listen on the same port\n    console.log('Listening for incomming HTTP requests.');\n\n    // Emit an event after 10 seconds\n    setTimeout(function() {\n        dumb.emit('client-update', {\n            clientId: 230948230,\n            oldEmail: 'tlhunter@gmail.com',\n            newEmail: 'tlhunter+github@gmail.com'\n        });\n    }, 10000);\n\nExample subscriptions.json\n===\n\n    [\n        {\n            \"event\": \"client-update\",\n            \"url\": \"http://localhost/listener.php\"\n        }\n    ]\n\nInstallation\n===\n\n    npm install dumb express\n    # copy server.js code from above\n    # copy subscriptions.json code from above\n    npm server.js\n\nDebugging\n===\n\nHere's a tool for Chrome that allows you to make various HTTP requests:\n\nhttps://chrome.google.com/webstore/detail/hgmloofddffdnphfgcellkdfbfbjeloo\n\nLicense\n===\n\nDual BSD/GPL\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftlhunter%2Fdumbpubsub","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftlhunter%2Fdumbpubsub","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftlhunter%2Fdumbpubsub/lists"}