{"id":16557654,"url":"https://github.com/twlite/nodeia","last_synced_at":"2025-03-27T13:35:49.970Z","repository":{"id":243551041,"uuid":"812715912","full_name":"twlite/nodeia","owner":"twlite","description":"Simplified networking api for Node.js","archived":false,"fork":false,"pushed_at":"2024-07-29T05:27:10.000Z","size":38,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-24T01:52:59.660Z","etag":null,"topics":["api","bun","http","nodejs","server","websocket"],"latest_commit_sha":null,"homepage":"https://npm.im/nodeia","language":"TypeScript","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/twlite.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":"2024-06-09T17:16:02.000Z","updated_at":"2024-06-10T17:35:05.000Z","dependencies_parsed_at":"2025-02-13T19:33:22.532Z","dependency_job_id":"b81c01cb-545f-4328-83bc-ade87bdc03ba","html_url":"https://github.com/twlite/nodeia","commit_stats":null,"previous_names":["twlite/nodeia"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twlite%2Fnodeia","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twlite%2Fnodeia/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twlite%2Fnodeia/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twlite%2Fnodeia/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/twlite","download_url":"https://codeload.github.com/twlite/nodeia/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245855193,"owners_count":20683469,"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":["api","bun","http","nodejs","server","websocket"],"created_at":"2024-10-11T20:08:09.566Z","updated_at":"2025-03-27T13:35:49.943Z","avatar_url":"https://github.com/twlite.png","language":"TypeScript","readme":"# Nodeia\n\nNodeia is a simplified networking api for Node. It is based on [Bun.serve](https://bun.sh/docs/api/http) api and is designed to be easy to use and understand.\n\n\u003e **Note:** Nodeia is still in development and is not yet ready for production use. You can help by testing it and reporting any issues you find.\n\n## Installation\n\n```sh\nnpm install nodeia\n```\n\n## Current features\n\n- ✅ HTTP server\n- ✅ WebSocket server\n- ✅ TCP server\n- ✅ TCP client\n- ❌ UDP server (todo)\n- ❌ UDP client (todo)\n\n## Usage\n\n### Simple HTTP server with WebSocket support\n\nHere is an example of a simple HTTP server that responds with \"Hello, world!\" to all requests. It also supports WebSocket connections.\n\nBy default, Nodeia listens on `0.0.0.0` and port `3000`. You can change this by passing the `hostname` and `port` options to the `serve` function. If the port given is already in use, Nodeia will use a random port. You can also manually pass port `0` to let the OS choose a random port.\n\n```js\nimport Nodeia from 'nodeia';\n\nNodeia.serve({\n  fetch(req, server) {\n    // Upgrade to WebSocket if the request is a WebSocket upgrade request\n    // do not return a response if the request is upgraded\n    if (server.upgrade(req)) return;\n\n    return new Response('Hello, world!', {\n      headers: {\n        'Content-Type': 'text/plain',\n      },\n    });\n  },\n  listening(hostname, port, server) {\n    // 👂 We are now listening to the requests\n    console.log(`Listening on ${server.url}`);\n  },\n  websocket: {\n    // Called when a WebSocket connection is opened\n    open(ws) {\n      ws.send('Hello, websocket!');\n    },\n    // Called when a WebSocket message is received\n    message(ws, message) {\n      const msg = String(message);\n      console.log('WebSocket message:', msg);\n      // Close the WebSocket connection if the message is 'close'\n      if (msg === 'close') ws.close(1000, 'Goodbye!');\n    },\n    // Called when a WebSocket connection is closed\n    close(ws, code, message) {\n      console.log('WebSocket closed');\n    },\n  },\n});\n```\n\n### Simple TCP server\n\nHere is an example of a simple TCP server that responds with \"Hello, world!\" to all connections.\n\n```js\nimport Nodeia from 'nodeia';\n\nNodeia.listen({\n  port: 8080,\n  hostname: 'localhost',\n  socket: {\n    open(socket) {\n      console.log('Socket opened');\n      socket.write('Hello, world!\\n');\n    },\n    close(socket) {\n      console.log('Socket closed');\n    },\n    data(socket, data) {\n      const msg = String(data);\n      console.log('Socket sent a data:', msg);\n\n      if (msg === 'close') socket.end();\n    },\n    drain(socket) {\n      console.log('Socket drained');\n    },\n    error(socket, err) {\n      console.error('Socket error:', err);\n    },\n  },\n});\n```\n\n### Simple TCP client\n\nHere is an example of a simple TCP client that connects to a TCP server and sends a message.\n\n```js\nimport Nodeia from 'nodeia';\n\nNodeia.connect({\n  hostname: 'localhost',\n  port: 3000,\n  socket: {\n    data(socket, data) {\n      console.log('Server sent data:', String(data));\n\n      if (String(data) === 'Hello, world!') socket.write('close');\n    },\n    open(socket) {\n      console.log('Connection opened');\n    },\n    close(socket) {\n      console.log('Connection closed');\n    },\n    drain(socket) {},\n    error(socket, error) {},\n\n    // client-specific handlers\n    connectError(socket, error) {}, // connection failed\n    end(socket) {}, // connection closed by server\n    timeout(socket) {}, // connection timed out\n  },\n});\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwlite%2Fnodeia","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftwlite%2Fnodeia","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwlite%2Fnodeia/lists"}