{"id":21353360,"url":"https://github.com/marketionist/node-testing-server","last_synced_at":"2025-07-12T21:31:47.312Z","repository":{"id":16283705,"uuid":"79665096","full_name":"Marketionist/node-testing-server","owner":"Marketionist","description":"Simple Node.js server to generate .html, .json, .js, .css, .jpg, .png pages for end-to-end and API testing","archived":false,"fork":false,"pushed_at":"2024-02-21T02:05:52.000Z","size":526,"stargazers_count":3,"open_issues_count":2,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-01T15:18:31.491Z","etag":null,"topics":["nodejs","server","test","test-automation","testing-tools"],"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/Marketionist.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":"2017-01-21T18:41:48.000Z","updated_at":"2023-12-15T15:24:25.000Z","dependencies_parsed_at":"2023-10-11T06:34:29.436Z","dependency_job_id":"faecc241-19a2-4234-a0cb-79322a565831","html_url":"https://github.com/Marketionist/node-testing-server","commit_stats":{"total_commits":92,"total_committers":2,"mean_commits":46.0,"dds":"0.010869565217391353","last_synced_commit":"de71c2305f676aec9c35a7448f268152c430c147"},"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Marketionist%2Fnode-testing-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Marketionist%2Fnode-testing-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Marketionist%2Fnode-testing-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Marketionist%2Fnode-testing-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Marketionist","download_url":"https://codeload.github.com/Marketionist/node-testing-server/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225834509,"owners_count":17531511,"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":["nodejs","server","test","test-automation","testing-tools"],"created_at":"2024-11-22T03:17:21.099Z","updated_at":"2024-11-22T03:17:21.654Z","avatar_url":"https://github.com/Marketionist.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# node-testing-server\n\n[![Actions Status](https://github.com/Marketionist/node-testing-server/workflows/Build%20and%20Test/badge.svg)](https://github.com/Marketionist/node-testing-server/actions)\n[![npm version](https://img.shields.io/npm/v/node-testing-server.svg)](https://www.npmjs.com/package/node-testing-server)\n[![NPM License](https://img.shields.io/npm/l/node-testing-server.svg)](https://github.com/Marketionist/node-testing-server/blob/master/LICENSE)\n\nSimple node.js server to generate .html, .json, .js, .css, .jpg, .png pages for end-to-end and API testing\n\n## Supported versions\n[Node.js](http://nodejs.org/):\n- 10.x\n- 11.x\n- 12.x\n- 13.x\n- 14.x\n- 15.x\n- 16.x\n- 17.x\n- 18.x\n- 19.x\n- 20.x\n\n## Installation\n`npm install node-testing-server --save-dev`\n\n## Importing and configuring\nYou can require node-testing-server and configure it like this:\n\n```javascript\nlet { nodeTestingServer } = require('node-testing-server');\n\n// Settings for node testing server\nnodeTestingServer.config = {\n    hostname: 'localhost',\n    port: 3001,\n    logsEnabled: 0,\n    pages: {\n        '/test.html': `\u003cul class=\"items\"\u003e\n                        \u003cli\u003eFirst\u003c/li\u003e\n                        \u003cli\u003eSecond\u003c/li\u003e\n                        \u003cli\u003eThird\u003c/li\u003e\n                        \u003cli\u003eFourth\u003c/li\u003e\n                        \u003cli\u003eFifth\u003c/li\u003e\n                        \u003cli\u003eSixth\u003c/li\u003e\n                        \u003cli\u003eSeventh\u003c/li\u003e\n                        \u003cli\u003eEighth\u003c/li\u003e\n                        \u003cli\u003eNinth\u003c/li\u003e\n                        \u003cli\u003eTenth\u003c/li\u003e\n                    \u003c/ul\u003e`\n    }\n};\n```\n\nAlso if you want to specify a status code that will be returned by the page:\n\n```javascript\nlet { nodeTestingServer } = require('node-testing-server');\n\n// Settings for node testing server\nnodeTestingServer.config = {\n    hostname: 'localhost',\n    port: 3001,\n    logsEnabled: 0,\n    pages: {\n        '/test.html': {\n            pageStatusCode: 201,\n            pageBody: `\u003cul class=\"items\"\u003e\n                        \u003cli\u003eFirst\u003c/li\u003e\n                        \u003cli\u003eSecond\u003c/li\u003e\n                        \u003cli\u003eThird\u003c/li\u003e\n                        \u003cli\u003eFourth\u003c/li\u003e\n                        \u003cli\u003eFifth\u003c/li\u003e\n                        \u003cli\u003eSixth\u003c/li\u003e\n                        \u003cli\u003eSeventh\u003c/li\u003e\n                        \u003cli\u003eEighth\u003c/li\u003e\n                        \u003cli\u003eNinth\u003c/li\u003e\n                        \u003cli\u003eTenth\u003c/li\u003e\n                    \u003c/ul\u003e`\n        }\n    }\n};\n```\n\nBy default logs are disabled (`logsEnabled` is set to 0). You can set\n`logsEnabled` config to one of 3 levels:\n- 0 - logs disabled\n- 1 - partial logs are enabled - prints out:\n  * incoming request METHOD, URL and outcoming response CODE\n  * pages that were generated or served\n- 2 - full logs are enabled - prints out:\n  * incoming request METHOD, URL and outcoming response CODE\n  * pages that were generated or served\n  * incoming request headers\n  * response time\n\n## Usage\nStart and stop server like this:\n\n```javascript\n// Start node testing server\nnodeTestingServer.start();\n\n// Stop node testing server\nnodeTestingServer.stop();\n```\n\nIf you will configure the `/test.html` server page as described in\n[Importing and configuring](#importing-and-configuring) section above, and send\na `GET` request to `http://localhost:3001/test.html`, then the server will\nreturn html page with:\n\n```html\n\u003cul class=\"items\"\u003e\n    \u003cli\u003eFirst\u003c/li\u003e\n    \u003cli\u003eSecond\u003c/li\u003e\n    \u003cli\u003eThird\u003c/li\u003e\n    \u003cli\u003eFourth\u003c/li\u003e\n    \u003cli\u003eFifth\u003c/li\u003e\n    \u003cli\u003eSixth\u003c/li\u003e\n    \u003cli\u003eSeventh\u003c/li\u003e\n    \u003cli\u003eEighth\u003c/li\u003e\n    \u003cli\u003eNinth\u003c/li\u003e\n    \u003cli\u003eTenth\u003c/li\u003e\n\u003c/ul\u003e\n```\n\nThere are also 2 default pre-configured pages that you can hit:\n\n1. Sending `GET` request to `http://localhost:3001/` will return:\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n\u003chead\u003e\n    \u003cmeta charset=\"UTF-8\"\u003e\n    \u003ctitle\u003eNode testing server - main page\u003c/title\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n    \u003ch1 class=\"title-main\"\u003eMain page of node testing server\u003c/h1\u003e\n    \u003cp\u003eThis page was constructed for testing purposes.\u003c/p\u003e\n    \u003cul\u003eMore info about \u003cstrong\u003enode-testing-server\u003c/strong\u003e:\n        \u003cli\u003e\u003ca href=\"https://github.com/Marketionist/node-testing-server\"\u003eon Github\u003c/a\u003e\u003c/li\u003e\n        \u003cli\u003e\u003ca href=\"https://www.npmjs.com/package/node-testing-server\"\u003eon npm\u003c/a\u003e\u003c/li\u003e\n    \u003c/ul\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\n\u003e Note: if you want to serve your own page from `http://localhost:3001/` - just\n\u003e create it in `public/index.html` in your root folder - otherwise it will be\n\u003e served from `node_modules/node-testing-server/public/index.html`\n\n2. Sending `POST` request to `http://localhost:3001/post` with `{\"test1\":1,\"test2\":\"Test text\"}`\nin the body will return a string with request headers and body:\n\n```\n`Incoming request headers: {\"content-type\":\"application/json\",\"connection\":\"close\",\"content-length\":\"31\",\"host\":\"localhost:3001\"}\nIncoming request body: {\"test1\":1,\"test2\":\"Test text\"}`\n```\n\nYou can see live examples of node-testing-server usage in\n[page-content-tests.js](https://github.com/Marketionist/node-testing-server/blob/master/tests/page-content-tests.js),\nin [Protractor tests](https://github.com/Marketionist/protractor-numerator/blob/master/test/spec.ts)\nand in [TestCafe tests](https://github.com/Marketionist/testcafe-cucumber-steps/blob/master/tests/testing-server.js)\n\n## Thanks\nIf this package was helpful to you, please give it a **★ Star**\non [GitHub](https://github.com/Marketionist/node-testing-server)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarketionist%2Fnode-testing-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarketionist%2Fnode-testing-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarketionist%2Fnode-testing-server/lists"}