{"id":19352795,"url":"https://github.com/thisconnect/port","last_synced_at":"2025-06-30T21:38:34.547Z","repository":{"id":1614241,"uuid":"2251199","full_name":"thisconnect/port","owner":"thisconnect","description":"Port is an Node.js module to communicate and control Pd (Pure Data)","archived":false,"fork":false,"pushed_at":"2015-02-12T07:14:59.000Z","size":3894,"stargazers_count":37,"open_issues_count":7,"forks_count":8,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-14T18:56:22.007Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/thisconnect.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}},"created_at":"2011-08-22T20:41:58.000Z","updated_at":"2025-04-24T00:37:24.000Z","dependencies_parsed_at":"2022-07-18T18:42:08.440Z","dependency_job_id":null,"html_url":"https://github.com/thisconnect/port","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/thisconnect/port","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thisconnect%2Fport","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thisconnect%2Fport/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thisconnect%2Fport/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thisconnect%2Fport/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thisconnect","download_url":"https://codeload.github.com/thisconnect/port/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thisconnect%2Fport/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260066108,"owners_count":22954133,"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-10T04:40:30.158Z","updated_at":"2025-06-30T21:38:34.481Z","avatar_url":"https://github.com/thisconnect.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Port\n\nA Node.js module to spawn and communicate with Pure Data (aka Pd).\n\n\n\nExample\n-------\n\n```js\nvar port = require('port');\n\nport({\n\t'read': 8004,\n\t'write': 8005,\n\t'basepath': __dirname,\n\t'flags': {\n\t\t'nogui': true,\n\t\t'stderr': true,\n\t\t'send': 'pd dsp 1, dsp 0',\n\t\t'path': 'relative/to/basepath',\n\t\t'open': 'patch.pd'\n\t}\n})\n.on('connect', function(){\n\tthis.write('Hello [netreceive]!;\\n');\n})\n.on('data', function(data){\n\tconsole.log('data receiving from [netsend]', data);\n})\n.on('stderr', function(buffer){\n\tconsole.log(buffer.toString());\n})\n.create();\n```\n\n\n\nInstall\n-------\n\n```bash\nnpm install port\n```\n\n\n\nAPI\n---\n\n### Constructor: Port\n\n```js\nvar Port = require('port');\n\nvar pd = new Port(options);\n```\n\nThe `new` keyword is optional.\n\n\n\n##### Options\n\n  - `host` - (string) The domain of the Pd process. Defaults to localhost.\n  - `read` - (number | null) The port to listen to Pd's [netsend]. \n  Defaults to null.\n  - `write` - (number | null) The port to connect to Pd's [netreceive]. \n  Defaults to null.\n  - `encoding` - (ascii | utf8 | base64 | hex | null)\n  The encoding of the read and write socket, \n  [nodejs.org/api/stream.html#stream_stream_setencoding_encoding](http://nodejs.org/api/stream.html#stream_stream_setencoding_encoding)\n  Defaults to null.\n  - `max` - (number) Limits amount of incoming connections. Defaults to 1.\n  - `basepath` - (string) -path flags are relative to basepath. Supports only flags object, but not flags array.\n  - `pd` - (string) The command or location to spawn the Pd process. \n  Defaults to an absolute path to the Pd binary on OS X.\n  Defaults to 'pd' on Linux.\n  - `debug` - (boolean) log parsed startup flags before spawning Pd.\n  - `flags` - (object) The command line arguments for the Pd process. \n  Expects an object of arguments. Read more about Pd's configuration flags on \n  [crca.ucsd.edu/~msp/Pd_documentation/x3.htm#s4](http://crca.ucsd.edu/~msp/Pd_documentation/x3.htm#s4) . \n  Defaults to {}. Array support is deprecated.\n\n\n\nMethods\n-------\n\n\n### Method: Port.create\n\n1. Spawns the Pd process.\n2. Listens for an incoming socket connection.\n3. Connects to on the write port.\n\nEach of the 3 steps are individually executed depending on the configuration.\n\n```js\npd.create();\n```\n\n\n\n### Method: Port.destroy\n\nKills the Pd process and ends all open connections. \n\n```js\npd.destroy();\n```\n\n\n\n### Method: Port.write\n\nSends a packet containing one or many messages to Pd's [netreceive].\n\nWARNING: write does not check if the write socket is ready and may error!\n\n```js\npd.write('Hello Pd!;\\n');\n```\n\n\n\n### Method: Port.setOptions\n\nReconfigure an instance, changes only take effect after destroy and create methods have been called.\n\n\n##### Arguments\n\n1. Data (object) - set configuration on an existing instance.\n\n```js\npd.setOptions({\n\t'read': 12345,\n\t'write': 12346,\n\t'basepath': __dirname,\n\t'flags': {\n\t\t'noprefs': true,\n\t\t'nogui': true,\n\t\t'stderr': true,\n\t\t'path': 'relatvie/path/to/dir',\n\t\t'open': 'patch.pd'\n\t}\n});\n```\n\n\n### Method: Port.isRunning\n\nReturns true when the instance is connected and it is safe to send data with the `write` method.\n\n\n\n### Method: Port.parseFlags\n\nInternal method, eventually useful for debugging. Turns flags object into an array. Adds dash prefix, omits flags that are falsy, supports path array, ensures -path and -open to be at the last position.\n\n\nEvents\n------\n\nPort is an event emitter see also\n[nodejs.org/api/events.html](http://nodejs.org/api/events.html)\n\n\n\n### Event: listening\n\nFires if the `read` port is specified and after Port.create is called.\nAt this point Port is waiting for an incoming TCP connection from Pd's [netsend].\n\n```js\npd.on('listening', function(){ });\n```\n\n\n\n### Event: connection\n\nFires when Pd connects and the `read` port is specified.\n\n```js\npd.on('connection', function(socket){ });\n```\n\n##### Arguments\n\n1. Socket (object) - Exposes the socket connection from [netsend].\n\n\n\n### Event: connect\n\nFires when Port connects to Pd on the write port. \n\n```js\npd.on('connect', function(socket){ });\n```\n\n##### Arguments\n\n1. Socket (object) - Exposes the socket connection to [netreceive].\n\n\n\n### Event: data\n\nFires when Pd sends a message with [netsend]. \n\n```js\npd.on('data', function(data){ });\n```\n\n##### Arguments\n\n1. Data - a buffer object or a string (if encoding is not null).\n\n\n\n### Event: stderr\n\nFires on every message that is written to the console the [print] object \nor anything else. This event is only available with `-stderr` or `-nogui` flag.\n\n```js\npd.on('stderr', function(buffer){ });\n```\n\n##### Arguments\n\n1. Buffer - the stderr buffer object.\n\n\n\n### Event: destroy\n\nFires after the destroy method is called. \n\n```js\npd.on('destroy', function(){ });\n```\n\n\n\nTests\n-----\n\nIf tests fail, the child process may be manually terminated with `killall pd`. \n\n```bash\nmake test\n```\n\n\n\nExamples\n--------\n\nSome examples are only proof of concept and are not optimized for best performance.\n\n```bash\nnode examples/testing/division.js\n\nnode examples/manipulation/server.js\n```\n\n\n\nRequires\n--------\n\n  - Vanilla Pure Data from \n  [crca.ucsd.edu/~msp/software.html](http://crca.ucsd.edu/~msp/software.html)\n  or Pd-extended from [puredata.info/downloads](http://puredata.info/downloads).\n  - Node.js from [nodejs.org](http://nodejs.org/).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthisconnect%2Fport","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthisconnect%2Fport","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthisconnect%2Fport/lists"}