{"id":18232750,"url":"https://github.com/emnawer/serverette","last_synced_at":"2026-01-25T20:16:12.110Z","repository":{"id":257823483,"uuid":"868349436","full_name":"emnawer/serverette","owner":"emnawer","description":"Node.js Testing Web Server","archived":false,"fork":false,"pushed_at":"2024-10-12T13:19:40.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-30T04:49:35.148Z","etag":null,"topics":["gulp","server","test","test-automation","testing-tools","web-application","web-development","web-development-tools"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/serverette","language":null,"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/emnawer.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-10-06T06:30:19.000Z","updated_at":"2024-10-12T13:07:34.000Z","dependencies_parsed_at":null,"dependency_job_id":"39973ec2-2a07-4671-867a-b2fe45b75585","html_url":"https://github.com/emnawer/serverette","commit_stats":null,"previous_names":["emnawer/serverette"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/emnawer/serverette","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emnawer%2Fserverette","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emnawer%2Fserverette/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emnawer%2Fserverette/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emnawer%2Fserverette/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/emnawer","download_url":"https://codeload.github.com/emnawer/serverette/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emnawer%2Fserverette/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28757716,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-25T16:32:25.380Z","status":"ssl_error","status_checked_at":"2026-01-25T16:32:09.189Z","response_time":113,"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":["gulp","server","test","test-automation","testing-tools","web-application","web-development","web-development-tools"],"created_at":"2024-11-04T14:03:33.081Z","updated_at":"2026-01-25T20:16:12.104Z","avatar_url":"https://github.com/emnawer.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Serverette — Node.js Testing Web Server\n\nThis is a web server as test bed you don't need to install Apache, Express, or other web server to test your HTML/CSS web application front-end.\n\nNote: This server is not for production. Serverette currently support only `GET`, `HEAD`, `POST`, `PUT`, `DELETE`, `OPTIONS`, and `PATCH` methods. `CONNECT` and `TRACE` are not supported.\n\nRoadmap: Find reason to add `CONNECT` and `TRACE` methods.\n\n\n## Installation\n\n```\nnpm install serverette --save-dev\n\n```\n\n\n## ES Module VS CommonJS\n\nTo know if your project is ES Module type look at the package.json file, it should have `\"type\": \"module\",` line.\nYour package.json should look something similar to this:\n\n```\n{\n  \"name\": \"nodejs\",\n  \"type\": \"module\",\n  \"version\": \"1.0.0\",\n  \"description\": \"\",\n  \"main\": \"index.js\",\n  \"scripts\": {\n    \"test\": \"echo \\\"Error: no test specified\\\" \u0026\u0026 exit 1\"\n  },\n  \"keywords\": [],\n  \"author\": \"\",\n  \"license\": \"ISC\",\n  \"dependencies\": {\n    \"@types/node\": \"^18.0.6\"\n  },\n  \"devDependencies\": {\n    \"serverette\": \"^0.9.0\"\n  }\n}\n```\n\n\n## Setup\n\nImport into your application ES module and create `__dirname`:\n\n```\n// import Serverette\nimport url from \"url\";\nimport { serverette } from \"serverette\";\n\n// get current directory\nconst __dirname = url.fileURLToPath(new URL(\".\", import.meta.url));\n```\n\nImport into your application in CommonJS (`__dirname` automatically available):\n```\n// import Serverette\nconst serverette = require(\"serverette\")\n```\n\nYou can import both Serverette and callbacks object (ES Module):\n```\n// import Serverette and callbacks\nimport { serverette, callbacks } from \"serverette\"\n```\n\nYou can import both Serverette and callbacks object (CommonJS:\n```\n// import Serverette and callbacks\nconst { serverette, callbacks } = require(\"serverette\")\n```\n\nNow you can create your web server with all defaults:\n```\n// create server \"test\" directory with test web files:\nserverette(__dirname + \"/test\");\n```\nReplace `/test` with the name of the test directory. The `__dirname` will return the full path of your working directory.\n\nImportant: You need at least one `index.htm` file and must be with `.htm` extension, not `.html`.\n\n\n## Usage\n\n```\n// Serverette acceptable parameters, rootDir is always required\n// callbacks is an object of these http types {get, post, put, options, patch}\nserverette(rootDir, port, mime, callbacks)\n```\n\n- **rootDir (required):** The full working directory can use the built-in `__dirname` variable and must add the directory of the tested files, for example: `__dirname + \"/test\"`.\n- **port** (optional): The default is 8080. Can choose anything you want.\n- **mime**  (optional): Built-in MIME according to [mozilla.org](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types). You can add your own MIME type if it is not there. MIME should be an array with objects of mime type and regex for the file extension. Example adding mp3 file type: `serverette(__dirname+\"/test\", 8080, [{ regex: /\\.mp3/, type: \"audio/mp3\" }])`\n- **callbacks {get, post, put, options, patch}** (optional): these are optional custom functions if the default behavior of printing data to the console is not satisfying.\n\n\n## HTTP Types Callback Behavior\n\n- **GET Callback** (optional): If no callback function provided, it will print the `URL` parameters (search query) data in console (terminal). Note: parameters returned by Serverette are in array pairs like: `[[\"key\",\"value\"],[\"key\",\"value\"],[\"key\",\"value\"]]`\n- **HEAD Callback** (optional): It will print `HEAD` with empty array data in console. Note, `HEAD` do not accept body/content in request.\n- **POST Callback** (optional): If no callback function provided, it will print the `POST` request data in console.\n- **PUT Callback** (optional): If no callback function provided, it will print the `PUT` data in console.\n- **DELETE Callback** (optional): Like `HEAD`, `DELETE` do not accept body (content) in request, but it will print DELETE in console with empty array.\n- **UPDATE Callback** (optional): Similar to `PUT`, if no callback function provided, it will print the `UPDATE` data in console.\n\n**NOTE:** For all callback above, you can use your custom callback function. Serverette will return an array of the streamed data as a parameter for your callback function like: `yourCallbackFunction([\"data stream 1\",\"data stream 2\"])` you may need your function to combine or iterate through them.\n\n\n## Understand Callback Functions\n\nServerette support callback function to catch the `request` body received and to hijack the `response` before sending it to browser/client. Your custom function/callback will get an array of the data stream as the first parameter and the response object as the second parameter.\nIf you want to add custom `POST` behavior, you ***need*** to import `callbacks` object first and add your custom `post` function. Note that `post` function is in lowercase.\n\n```\nimport { serverette, callbacks } from \"serverette\"\n\ncallbacks.post = function(array,response){\n\n\t// printing POST body to the console:\n    console.log(\"log array of POST\", array)\n\n    // Write response (also can redirect if you want) and close connection\n    response.writeHead(200, { 'Content-Type': 'text/html' })\n    response.end(\"POST data received!\")\n}\nserverette(__dirname + \"/test\",'','',callbacks);\n\n```\n\n## Full Example\n\n```\nimport url from \"url\";\nimport { serverette, callbacks } from \"serverette\"\n\n// Get current dir\nconst __dirname = url.fileURLToPath(new URL(\".\", import.meta.url));\n\n// add custom POST behavior:\ncallbacks.post = function(array,response){\n    console.log(\"log array of POST\", array)\n    response.writeHead(200, { 'Content-Type': 'text/html' })\n    response.end(\"POST data received!\")\n}\n\n// add custom mime:\nconst myMp3Mime = [{ regex: /\\.mp3/, type: \"audio/mp3\" }]\n\nserverette(__dirname + \"/test\", 8080, myMp3Mime, callbacks);\n```\nTerminal output will be something similar to this:\n```\nServerette port #: 8080\n======================\nGET: / MIME: text/html\nGET: /w3e.css MIME: text/css\nGET: /w3-theme-blue-grey.css MIME: text/css\nGET: /h5p-font-awesome.min.css MIME: text/css\nGET: /w3e.js MIME: text/javascript\nGET: /snow.jpg MIME: image/jpeg\nGET: /forest.jpg MIME: image/jpeg\nGET: /car.jpg MIME: image/jpeg\nGET: /mountains.jpg MIME: image/jpeg\nGET: /lights.jpg MIME: image/jpeg\nHEAD: []\nDELETE: []\nPUT: [ '{\"test\":\"testing PUT method\"}' ]\nPATCH: [ '{\"test\":\"testing PATCH method\"}' ]\nPOST: [ '{\"test\":\"testing POST method\"}' ]\nOPTIONS: [ '{\"test\":\"testing OPTIONS method\"}' ]\n=============================\nURL(GET) parameters found!\nURLSearchParams { 'v' =\u003e '4.5.0' }\nv 4.5.0\n=============================\nGET: /fontawesome-webfont.woff2 MIME: font/woff\nGET: /fontawesome-webfont.woff2 MIME: font/woff2\nGET: /favicon.ico MIME: image/x-icon\nPOST: [ 'name=Joe\u0026email=Joe%40example.com\u0026subject=Register+me\u0026gender=male' ]\n\n```\n\n## Support, Feedback \u0026 Issues\n\nYour contribution is very important, please, visit this link: (https://github.com/emnawer/serverette/issues).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femnawer%2Fserverette","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femnawer%2Fserverette","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femnawer%2Fserverette/lists"}