{"id":19358846,"url":"https://github.com/kathan/message-agent","last_synced_at":"2026-07-01T15:31:35.366Z","repository":{"id":57295192,"uuid":"124574905","full_name":"kathan/message-agent","owner":"kathan","description":null,"archived":false,"fork":false,"pushed_at":"2018-04-12T15:48:44.000Z","size":31,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-07T13:32:48.677Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/kathan.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":"2018-03-09T17:53:58.000Z","updated_at":"2018-04-12T15:48:45.000Z","dependencies_parsed_at":"2022-08-30T18:52:01.996Z","dependency_job_id":null,"html_url":"https://github.com/kathan/message-agent","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kathan%2Fmessage-agent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kathan%2Fmessage-agent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kathan%2Fmessage-agent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kathan%2Fmessage-agent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kathan","download_url":"https://codeload.github.com/kathan/message-agent/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240475230,"owners_count":19807292,"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-11-10T07:13:18.370Z","updated_at":"2025-11-07T11:02:40.230Z","avatar_url":"https://github.com/kathan.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# file-agent\nA lightweight library written in node.js to automate hot folders.\n```js\n/*\nfile-agent test\n*/\nconst Async = require('async');\nconst formidable = require('formidable');\nconst express = require('express');\nconst fs = require('fs');\nconst app = express();\nconst FileAgent = require('../index.js');\nconst path = require('path');\n\nconst port = 4536;\nconst agent_1_name = 'test-agent1';\nconst agent_2_name = 'test-agent2';\n\napp.set(\"json spaces\", 2);\napp.use((req, res, next)=\u003e{\n  if (req.method.toLowerCase() == 'post') {\n    var form = new formidable.IncomingForm();\n    form.parse(req, (err, fields, files) =\u003e {\n      if(err){return;}\n      req.body = fields;\n      for(var i in files){\n        files[i].data = fs.readFileSync(files[i].path);\n      }\n      req.files = files;\n      next();\n    });\n    return;\n  }\n  next();\n});\n\nAsync.series([\n  (next)=\u003e{\n    app.listen(port, () =\u003e {\n      console.log(`app listening on ${port}`);\n      next();\n    });\n  },\n  (next)=\u003e{\n    /*\n    Create an agent that will pass files to a second agent.\n    */\n    var fa1 = FileAgent(app, path.resolve(__dirname, 'fa'), agent_1_name, `http://localhost:${port}/${agent_2_name}`);\n    \n    fa1.on('ready', (err)=\u003e{\n      if(err){return next(err);}\n      console.log(`Running agent ${agent_1_name}`);\n      //==== Start the first agent ====\n      fa1.start();\n      next();\n    });\n    \n    fa1.on('file', (file, payload, done)=\u003e{\n      payload.count++;\n      console.log('payload1', payload);\n      done(true);\n    });\n    \n    fa1.on('error', (err)=\u003e{\n      console.error('error 1', err);\n    });\n  },\n  (next)=\u003e{\n    /*\n    Create a second agent that passes received files back to the first agent.\n    */\n    var fa2 = FileAgent(app, path.resolve(__dirname, 'fa'), agent_2_name);\n    \n    fa2.emit('ready', `http://localhost:${port}/${agent_1_name}`, (err)=\u003e{\n      if(err){return next(err);}\n      console.log(`Running agent ${agent_2_name}`);\n      //==== Start the second agent ====\n      fa2.start();\n      next();\n    });\n    \n    fa2.on('file', (file, payload, done)=\u003e{\n      var result = true;\n  \t\t//==== Stop after 5 round trips ====\n      if(payload.count == 5){\n        fa2.stop();\n        result = false;\n      }\n      done(result);\n    });\n    \n    fa2.on('error', (err)=\u003e{\n      console.error('error 2', err);\n    });\n  }],\n  (err)=\u003e{\n    if(err){return console.error('Error', err);}\n  }\n);\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkathan%2Fmessage-agent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkathan%2Fmessage-agent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkathan%2Fmessage-agent/lists"}