{"id":21650831,"url":"https://github.com/hlev/nodemc-hello","last_synced_at":"2026-04-30T20:32:36.800Z","repository":{"id":68687748,"uuid":"149073165","full_name":"hlev/nodemc-hello","owner":"hlev","description":"Assignment #1","archived":false,"fork":false,"pushed_at":"2018-09-27T06:36:42.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-19T02:53:28.254Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hlev.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":"2018-09-17T05:27:15.000Z","updated_at":"2018-09-27T06:36:43.000Z","dependencies_parsed_at":"2023-05-07T04:57:52.942Z","dependency_job_id":null,"html_url":"https://github.com/hlev/nodemc-hello","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hlev/nodemc-hello","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hlev%2Fnodemc-hello","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hlev%2Fnodemc-hello/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hlev%2Fnodemc-hello/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hlev%2Fnodemc-hello/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hlev","download_url":"https://codeload.github.com/hlev/nodemc-hello/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hlev%2Fnodemc-hello/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32476682,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-30T13:12:12.517Z","status":"ssl_error","status_checked_at":"2026-04-30T13:12:06.837Z","response_time":57,"last_error":"SSL_read: 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":[],"created_at":"2024-11-25T07:42:56.420Z","updated_at":"2026-04-30T20:32:36.795Z","avatar_url":"https://github.com/hlev.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nodemc-hello\n### A simple somewhat-RESTful JSON(ish) API\nThis is submission to The Node.js Master Class, Assignment #1, by Pirple.\n\nResponds to `GET /ping`, `GET /hello`, `POST /hello` and `OPTIONS` sent to these URIs.\n\nResponds with `405 Method Not Allowed` if the resource does not implement the request's otherwise valid HTTP method.\nResponds with `404 Not Found` to requests made to unknown resources, `500 Internal Server Error`, you know when...\n  \n## Resources\nResources represent REST API entities and can be registered with the API with a URI and handlers for different HTTP methods.\n\n```javascript\n// Well, `/ping` does not respond with JSON\napi.add(\n    new Resource('/ping')\n        .get((data, req, res) =\u003e { res.end('pong\\n'); })\n        .post((data, req, res) =\u003e { /* handler code */ })\n);\n```\n\nHandlers have full control over the `request` and `response` objects.\n`data` passed to every handler contains the request headers, the parsed search parameters, the URL hash and the parsed request body for convenience.\n\n## Configuration\n`config.json` may contain configuration for one or more environments.\n\n```text\n{\n \u003cenv\u003e : \u003cconfig_object\u003e,\n \u003canother_env\u003e: \u003cconfig_object\u003e,\n ...\n}\n```\n\nThe app determines environment from the NODE_ENV environment variable and defaults to \"development\".\n\nThen it attempts to read the specified configuration from `config.json`. In the lack of the file or a matching configuration object/key\nit will fallback to defaults.\n\nConfiguration in the app can be accessed via the `Config` helper.\nA default value can be provided for when the configuration value is missing or is of the wrong type. An example of the\nlatter is present in the repo as is.\n\n```javascript\nconst config   = require('./config')('./config.json');\nconst useHttps = config.bool('https.startServer', false);\n\nif (useHttps) {\n    // do stuff...\n}\n```\n\nThis corresponds to a `config.json` scheme as follows:\n```text\n{\n \"\u003cenvironment\u003e\": {\n   \"https\": {\n     \"startServer\": \u003ctrue/false\u003e\n   }\n }\n}\n```\n\n## TLS\nIf you want TLS, generate a new private key and self-signed certificate in the `./tls` folder.\n```bash\nopenssl req -newkey rsa:2048 -nodes -x509 -days 999 -out cert.pem -keyout key.pem\n```\nThen set `https.startServer` to `true` in `config.json` before starting the app.\n\n\n## Notes\nThere are a couple of things that can immediately be improved:\n- Since it is supposed to be a JSON API, the responsibility of the JSON parsing/serialization and e.g. the setting of\nthe `Content-Type` response header could be done outside the actual handlers.\n- Parsing of the inbound request is far from perfect. There's no validation on request body, for one.\n- There are no tests (yet) either\n- The handlers' raw access to `request` and `response` is not optimal. And so on...\n\nThe submission does not stick to the letter of the assignment specs, but I wanted a refresher-project to try a couple of\nES6 features I've seldom used and play around with alternative care-free approaches to structuring the implementation of\na REST API.\n\nThere are a couple of (hopefully interesting) generic JS techniques in there as well that may inspire others, especially\nif they are new to JS/Node.js and like to read, explore (and judge) others' code.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhlev%2Fnodemc-hello","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhlev%2Fnodemc-hello","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhlev%2Fnodemc-hello/lists"}