{"id":22218584,"url":"https://github.com/megahertz/pascal-nodejs-ipc","last_synced_at":"2025-04-11T11:07:43.715Z","repository":{"id":66074176,"uuid":"182121605","full_name":"megahertz/pascal-nodejs-ipc","owner":"megahertz","description":"Free Pascal library for communicating with a parent Node.js process through IPC ","archived":false,"fork":false,"pushed_at":"2019-04-26T20:02:02.000Z","size":503,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-03T15:17:56.535Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Pascal","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/megahertz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-04-18T16:27:10.000Z","updated_at":"2023-03-17T12:16:10.000Z","dependencies_parsed_at":"2023-02-20T19:30:50.394Z","dependency_job_id":null,"html_url":"https://github.com/megahertz/pascal-nodejs-ipc","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/megahertz%2Fpascal-nodejs-ipc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/megahertz%2Fpascal-nodejs-ipc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/megahertz%2Fpascal-nodejs-ipc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/megahertz%2Fpascal-nodejs-ipc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/megahertz","download_url":"https://codeload.github.com/megahertz/pascal-nodejs-ipc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248381761,"owners_count":21094525,"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-12-02T22:27:11.856Z","updated_at":"2025-04-11T11:07:43.699Z","avatar_url":"https://github.com/megahertz.png","language":"Pascal","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pascal-nodejs-ipc\n\nFree Pascal library for communicating with a parent Node.js process through\nInter Process Communications (IPC). \n\nTested with FPC v3.0.4, v3.1.1, node v11.9.0 on Linux x64\n\n[Example project](example)\n\n## Usage\n\n**parent.js**\n```js\nconst { spawn } = require('child_process');\n\nconst proc = spawn('./dist/child', {\n  stdio: ['pipe', 'pipe', 'pipe', 'ipc'],\n});\n\n// Using built-in Node.js IPC\nproc.on('message', msg =\u003e console.log('parent, new message:', msg));\nproc.send({ source: 'Node.js' });\n```\n\n**child.pas**\n```pascal\nprogram child;\n\nuses\n  {$ifdef Unix}cthreads,{$endif} nodeipc;\n\ntype\n  TApplication = class\n  private\n    FNodeIpc: TNodeIpcProtocol;\n    procedure OnMessage(Message: Variant);\n  public\n    procedure Run;\n  end;\n\nprocedure TApplication.OnMessage(Message: Variant);\nbegin\n  WriteLn('child, new message: ', Message);\nend;\n\nprocedure TApplication.Run;\nbegin\n  FNodeIpc := TNodeIpcProtocol.Create;\n  FNodeIpc.OnMessage := @OnMessage;\n  FNodeIpc.Send('{\"source\":\"Free Pascal\"}');\n\n  WriteLn('Press any key to exit');\n  ReadLn();\nend;\n\nvar\n  App: TApplication;\nbegin\n  App := TApplication.Create;\n  App.Run;\nend.\n\n```\n\n## How Node.js built-in IPC module works\n\n- Node.js passes a bi-directional IPC stream to a child process as a file\ndescriptor.\n```js\nconst proc = spawn('./dist/child', {\n  stdio: ['pipe', 'pipe', 'pipe', 'ipc'],\n});\n```\n\n- To send a message trough this stream, each process can send JSON encoded\n  strings separated by a new line char.\n\n- To get the exact file descriptor, a child process reads NODE_CHANNEL_FD\n  environment variable.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmegahertz%2Fpascal-nodejs-ipc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmegahertz%2Fpascal-nodejs-ipc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmegahertz%2Fpascal-nodejs-ipc/lists"}