{"id":15367951,"url":"https://github.com/connorwiseman/nicer-server","last_synced_at":"2026-05-04T03:34:35.920Z","repository":{"id":57311070,"uuid":"103484195","full_name":"ConnorWiseman/nicer-server","owner":"ConnorWiseman","description":"A nicer HTTP(S) server.","archived":false,"fork":false,"pushed_at":"2018-06-26T16:05:04.000Z","size":73,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-02T00:48:39.359Z","etag":null,"topics":["http","https","nodejs","server"],"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/ConnorWiseman.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}},"created_at":"2017-09-14T04:03:45.000Z","updated_at":"2018-06-26T16:05:06.000Z","dependencies_parsed_at":"2022-09-07T12:01:05.769Z","dependency_job_id":null,"html_url":"https://github.com/ConnorWiseman/nicer-server","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/ConnorWiseman%2Fnicer-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ConnorWiseman%2Fnicer-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ConnorWiseman%2Fnicer-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ConnorWiseman%2Fnicer-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ConnorWiseman","download_url":"https://codeload.github.com/ConnorWiseman/nicer-server/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245926605,"owners_count":20695079,"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":["http","https","nodejs","server"],"created_at":"2024-10-01T13:27:12.231Z","updated_at":"2026-05-04T03:34:35.895Z","avatar_url":"https://github.com/ConnorWiseman.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nicer-server\n\n[![npm](https://img.shields.io/npm/v/nicer-server.svg?style=flat-square)](https://www.npmjs.com/package/nicer-server)\n![Node.js](https://img.shields.io/badge/node.js-%3E=_7.6.0-blue.svg?style=flat-square)\n[![Build Status](https://img.shields.io/travis/ConnorWiseman/nicer-server/master.svg?style=flat-square)](https://travis-ci.org/ConnorWiseman/nicer-server) [![Coverage](https://img.shields.io/codecov/c/github/ConnorWiseman/nicer-server.svg?style=flat-square)](https://codecov.io/gh/ConnorWiseman/nicer-server)\n[![Dependencies Status](https://david-dm.org/ConnorWiseman/nicer-server/status.svg?style=flat-square)](https://david-dm.org/ConnorWiseman/nicer-server)\n[![devDependencies Status](https://david-dm.org/ConnorWiseman/nicer-server/dev-status.svg?style=flat-square)](https://david-dm.org/ConnorWiseman/nicer-server?type=dev)\n[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://github.com/ConnorWiseman/nicer-server/blob/master/LICENSE)\n\n\u003e A nicer HTTP(S) server.\n\nCreates and manages an HTTP(S) server based on a specified callback function, maintaining a Map of active Socket connections to gracefully terminate them when the server closes. All methods return Promises.\n\nThoroughly tested with the built-in [`http@0.0.0`](https://nodejs.org/api/http.html) and [`https@1.0.0`](https://nodejs.org/api/https.html) modules, and compatible with the [`bluebird@3.5.1`](https://github.com/petkaantonov/bluebird/), [`express@4.16.3`](https://github.com/expressjs/express), [`koa@2.5.1`](https://github.com/koajs/koa), [`ws@5.2.1`](https://github.com/websockets/ws), and [`socket.io@2.1.1`](https://github.com/socketio/socket.io) modules.\n\n\n## Installation\n```shell\nnpm install --save nicer-server\n```\n\n## Usage\n\n### Basic HTTP server\n\n```javascript\nconst server = require('nicer-server');\n\nlet options = {\n  port: 3000\n};\n\nserver((req, res) =\u003e {\n  res.end('Hello, world!');\n}, options).listen();\n```\n\n\n### Koa\n\n```javascript\nconst Koa    = require('koa');\nconst server = require('nicer-server');\n\nlet options = {\n  port: 3000\n};\n\nlet app = new Koa;\n\napp.use(async (ctx) =\u003e {\n  ctx.body = 'Hello, world!';\n});\n\nserver(app.callback(), options).listen();\n```\n\n\n### Express\n\n```javascript\nconst express = require('express');\nconst server  = require('nicer-server');\n\nlet options = {\n  port: 3000\n};\n\nlet app = express();\n\napp.get('/', (req, res) =\u003e {\n  res.end('Hello, world!');\n});\n\nserver(app, options).listen();\n```\n\n\n## API\n\n### #close\n\nDestroys remaining sockets to terminate active connections, then closes the underlying HTTP(S) server.\n\n\n### #listen\n\nCreates a new HTTP(S) server, adding event handlers to the `request` and `connection` events to toggle an `idle` flag on incoming Sockets and destroy them if necessary. Resolves once the server is listening.\n\n\n### #restart\n\nRestarts the server. Calls `#close`, then `#listen`.\n\n\n## Options\n\n```javascript\nconst bluebird = require('bluebird');\nconst fs       = require('fs');\n\n// Options for an HTTPS server listening on port 443,\n// using the Bluebird Promise library\nlet options = {\n  logger:  'https',\n  port:    443,\n  Promise: bluebird,\n  ssl: {\n    key:  fs.readFileSync('key.pem'),\n    cert: fs.readFileSync('cert.pem')\n  }\n};\n```\n\n\n### logger\n`nicer-server` relies on the [`debug`](https://github.com/visionmedia/debug) module for debugging messages. The name of the logger used by this module may be customized by specifying an optional string. Defaults to `server`.\n\n\n### port\nThe port to listen on. Defaults to `3000`.\n\n\n### Promise\nThe constructor function to create internal Promises from. Defaults to the built-in `Promise` object.\n\n\n### ssl\nAn object of SSL options. Defaults to `null`. If `null`, the underlying server instance will be created using `http#createServer`. See [the HTTPS Node.js documentation](https://nodejs.org/api/https.html#https_https_createserver_options_requestlistener) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fconnorwiseman%2Fnicer-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fconnorwiseman%2Fnicer-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fconnorwiseman%2Fnicer-server/lists"}