{"id":20038211,"url":"https://github.com/abourass/nodejs-server-examples","last_synced_at":"2026-05-12T10:33:20.108Z","repository":{"id":99006041,"uuid":"172561323","full_name":"Abourass/nodeJS-Server-Examples","owner":"Abourass","description":"A few short examples of different server configurations for Node.JS","archived":false,"fork":false,"pushed_at":"2020-08-21T15:35:55.000Z","size":16,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-02T06:27:36.857Z","etag":null,"topics":["api","example","examples","node","node-js","nodejs","server","stream"],"latest_commit_sha":null,"homepage":"","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/Abourass.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-02-25T18:28:54.000Z","updated_at":"2023-03-04T05:00:02.000Z","dependencies_parsed_at":null,"dependency_job_id":"19ecf3b4-b85f-4a43-8f4a-4d3a6a48f47b","html_url":"https://github.com/Abourass/nodeJS-Server-Examples","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Abourass/nodeJS-Server-Examples","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Abourass%2FnodeJS-Server-Examples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Abourass%2FnodeJS-Server-Examples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Abourass%2FnodeJS-Server-Examples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Abourass%2FnodeJS-Server-Examples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Abourass","download_url":"https://codeload.github.com/Abourass/nodeJS-Server-Examples/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Abourass%2FnodeJS-Server-Examples/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32934540,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-12T09:19:52.626Z","status":"ssl_error","status_checked_at":"2026-05-12T09:17:33.438Z","response_time":102,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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","example","examples","node","node-js","nodejs","server","stream"],"created_at":"2024-11-13T10:26:48.914Z","updated_at":"2026-05-12T10:33:20.073Z","avatar_url":"https://github.com/Abourass.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Node Server Examples\nThese are some simple networking examples for NodeJS that I learned while reading *Networking Patterns* by *Pedro Teixeira*\n\n### Table of Contents\nExample | Description\n------- | -----------\n#1 | [Raw Server](#1)\n#2 | [Flawed Basic Service](#2)\n#3 | [Basic Service as a Stream](#3)\n#4 | [JSON Streams and Event Gateways](#4)\n\n## Installation:\nDownload and open your preferred terminal within the folder, then run:\n\n`npm i`\n\n## Running the Examples:\nYou can use any of the run commands in the package.json file\n\n\u003ca name=\"1\"\u003e\u003c/a\u003e\n## #1: Raw Server\nAn extremely basic TCP echo server. Run:\n\n`node rawServer.js`\n\nNow that the server is running use Telnet or NetCat to connect:\n\nWindows:\n```telnet localhost 9000```\n\nLinux/Unix: \n```nc localhost 9000```\n\nOnce connected, type whatever you want. In the terminal window which you started running the server you should see log statements that log when you connect, and the raw buffer data (printing out each byte). If you are curious what it does, just open the file, I've commented enough to highlight how it works. \n\n\u003ca name=\"2\"\u003e\u003c/a\u003e\n## #2: A Flawed Basic Service\nA service which returns the provided string in all caps. This service was built with a flaw, it provides no back-pressure. If the rate at which a client connection sends characters is lower than the rate it receives (for instance, if the downstream available bandwidth is higher than the upstream one), the process memory will grow until it is exhausted. What's needed here is a mechanism by which the incoming TCP stream is paused if the level of memory pending on the outgoing buffer gets high enough. Run via:\n\n```node capitalizingServer.js```\n\nNow that the server is running use Telnet or NetCat to connect:\n\nWindows:\n```telnet localhost 9000```\n\nLinux/Unix: \n```nc localhost 9000```\n\nOnce connected, type whatever you want, and it will be returned in all caps.\n\n\u003ca name=\"3\"\u003e\u003c/a\u003e\n## #3: A Basic Service as a Stream\nThis is an implementation of the same capitalization service as #2, however, it's implemented as a stream in order to solve the flaw outlined in example #2. So, rather than listening for TCP 'data' events we start a stream, then pipe the connection into the stream, and finally, pipe the stream back into the service. Run via:\n\n```node capitalizingServer2.js```\n\nNow that the server is running use Telnet or NetCat to connect:\n\nWindows:\n```telnet localhost 9000```\n\nLinux/Unix: \n```nc localhost 9000```\n\nOnce connected, type whatever you want, and it will be returned in all caps.\n\n\u003ca name=\"4\"\u003e\u003c/a\u003e\n## #4: JSON Streams and Event Gateways\nIn this example the TCP server accepts events from domotic devices (thermometers, lights, etc..) in the form of a JSON object.\nThis example uses the '*json-duplex-stream*' package from NPM in order to create a service that accepts and replies with a streamable format of JSON. \nJSON isn't particularly stream-friendly by default, as JSON is only valid once the entire object is transmitted, making a stream somewhat useless. However, if none of the transmitted objects, when serialised, contain new-line characters, we can safely separate each one of the main objects with a new line character. The default Node.js JSON encoding doesn't introduce any new-line character, and for those existing in strings within the object, it encodes them with *\"\\n\"*. \n\nExample:\n```\n{\"a\":1,\"b\":true,c:\"this is a newline-terminated string\\n\"}\n{\"d\":2,\"e\":false,f:\"this is another newline-terminated string\\n\"}\n```  \nBack to our event gateway example, each device will connect to this service and send it events throughout time. The gatway service saves each of these events into a persisted queue for further processing by other process. Each recieved object represents an event, and each event have a unique `id` field. Once done saving the event into the queue, the gateway replies with a message confirming that the events were saved. Run via:\n\n```node gatewayServer.js```\n\nNow that the server is running use Telnet or NetCat to connect:\n\nWindows:\n```telnet localhost 8000```\n\nLinux/Unix: \n```nc localhost 8000```\n\nOnce connected, type: `{\"when\":\"2019-02-25T14:28:49-07:00\", \"type\":\"temperature\", \"reading\":69.8, \"units\":\"F\", \"id\":\"5f18453d-1907-48bc-abd2-ab6c24bc197d\"}`\n\nYou should get back a confirmation like: `{\"id\":\"5f18453d-1907-48bc-abd2-ab6c24bc197d\", \"success\":true}`\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabourass%2Fnodejs-server-examples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fabourass%2Fnodejs-server-examples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabourass%2Fnodejs-server-examples/lists"}