{"id":20077575,"url":"https://github.com/digitaledgeit/js-simple-server-setup","last_synced_at":"2025-03-02T12:44:51.953Z","repository":{"id":25954521,"uuid":"29396220","full_name":"digitaledgeit/js-simple-server-setup","owner":"digitaledgeit","description":"A library for creating a simple server with little effort.","archived":false,"fork":false,"pushed_at":"2016-03-08T15:45:14.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-25T12:03:21.727Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/digitaledgeit.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}},"created_at":"2015-01-17T16:00:41.000Z","updated_at":"2016-03-08T15:33:34.000Z","dependencies_parsed_at":"2022-08-06T08:00:25.387Z","dependency_job_id":null,"html_url":"https://github.com/digitaledgeit/js-simple-server-setup","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digitaledgeit%2Fjs-simple-server-setup","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digitaledgeit%2Fjs-simple-server-setup/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digitaledgeit%2Fjs-simple-server-setup/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digitaledgeit%2Fjs-simple-server-setup/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/digitaledgeit","download_url":"https://codeload.github.com/digitaledgeit/js-simple-server-setup/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241509619,"owners_count":19974071,"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":[],"created_at":"2024-11-13T15:09:04.322Z","updated_at":"2025-03-02T12:44:51.913Z","avatar_url":"https://github.com/digitaledgeit.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# simple-server-setup\n\nA library for creating a simple server with little effort.\n\nBootstrap an `express` app in just a few lines. Useful for testing scripts that use a HTTP client e.g.  [go-fetch](https://www.npmjs.com/package/go-fetch) or [browserbot](https://www.npmjs.com/package/browserbot).\n\n## Installation\n\n    npm install --save-dev simple-server-setup\n\n## Usage\n\nA simple HTTP server:\n\n```javascript\n\nconst server = require('simple-server-setup');\n\nserver.create(app =\u003e {\n\n    app.get('/', (req, res) =\u003e {\n      res.send('http - simple-server-setup');\n    });\n\n  })\n  .then(server =\u003e console.log(`Listening at ${server.url}`))\n;\n\n\n```\n\nA simple HTTPS server:\n\n```javascript\n\nconst server = require('simple-server-setup');\n\nconst options = {\n  secure: true,\n  key: __dirname + '/server.key',\n  cert: __dirname + '/server.cert'\n};\n\nserver.create(options, app =\u003e {\n\n    app.get('/', (req, res) =\u003e {\n      res.send('https - simple-server-setup');\n    });\n\n  })\n  .then(server =\u003e console.log(`Listening at ${server.url}`))\n;\n\n```\n\nA unit test to check the HTTP client has sent the Content-Type header:\n\n```javascript\n\nconst assert  = require('assert');\nconst client  = require('go-fetch');\nconst server  = require('simple-server-setup');\n\nit('should set the Content-Type', function (done) {\n\n  server.create(app =\u003e {\n    app.get('/', (req, res) =\u003e {\n      try {\n        assert.equal(req.headers['content-type'], 'text/x-foo');\n      } catch (err) {\n        done(err);\n      }\n      res.send('test - simple-server-setup');\n    });\n  })\n    .then(server =\u003e {\n      client().get(server.url, {'Content-Type': 'text/x-foo'}, (err, res) =\u003e {\n        if (err) throw err;\n        res.getBody().on('data', () =\u003e {/* do nothing */\n        });\n        res.getBody().on('end', () =\u003e server.close(done));\n      });\n\n    })\n    .catch(err =\u003e console.log(err))\n  ;\n\n});\n\n```\n\n## API\n\n### Methods\n\n#### .create([options], callback) : Promise\u003chttp.Server\u003e\n    \nCreate a new server with the specified options.\n\nOptions:\n\n\t @param   {Object}    [options]             The server options\n\t @param   {Boolean}   [options.host]        The server host - localhost\n\t @param   {Boolean}   [options.port]        The server port - 3000\n\t @param   {Boolean}   [options.keepAlive]   Whether the server should keep connections alive (turning this on will take longer for the server to shutdown between tests - false\n\t @param   {Boolean}   [options.secure]      Whether the server should serve requests on HTTPS - false\n\t @param   {Boolean}   [options.key]         The path to the server key - server.key\n\t @param   {Boolean}   [options.cert]        The path to the server certificate - server.cert\n\t @param   {Function}  callback              A function to configure the express instance\n    \n### Events\n\n## Miscellaneous\n\n### Generating a self-signed key and certificate for a HTTPS server\n\n    openssl req -nodes -new -x509 -keyout server.key -out server.cert\n     \n## Change log\n\n### 0.2.0\n\n- break: return a promise instead of an event emitter\n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) 2016 James Newell\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdigitaledgeit%2Fjs-simple-server-setup","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdigitaledgeit%2Fjs-simple-server-setup","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdigitaledgeit%2Fjs-simple-server-setup/lists"}