
Product
Introducing Webhook Events for Alert Changes
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.
A runsv wrapper around http.Server.
const runsv = require('runsv').create();
const createHTTPService = require('runsv-http');
const express = require('express');
const app = express();
const PORT = 3000;
/* set up your app */
app.get('/', (req, res) => res.end('hello'));
// configure the runsv-http service
const myWeb = createHTTPService('myWeb') // optionally you can set a custom name
.createServer(app) // same signature as http.createServer()
.listen(PORT); // same signature as server.listen. DO NOT include the callback.
runsv.addService(myWeb);
runsv.start(function(err){
const {myWeb} = runsv.getClients();
console.log(`listening at port ${PORT}`);
});
//...
In node you usually create an instance of an http server like this:
const http = require('http');
const port = 3000;
function listener(req, res){
res.end('hello');
}
const server = http.createServer(listener);
server.listen(port, function(err){
console.log(`listening at ${port}`);
});
Both createServer() and listen() accept optional params.
The goal of this API is to be as close as possible to the original node API.
const runsv = require('runsv').create();
const port = 3000;
const createService = require('runsv-http');
function listener(req, res){
res.end('hello');
}
const server = createService()
.createServer(listener)
.listen(port);
runsv.addService(server);
runsv.start(function(err){
console.log(`listening at ${port}`);
});
//...
#createService([name]) returns a runsv service wrapper around original nodejshttp.server.
[name='http'] runsv service name. Optional. By default is http.runsv service. This service also exposes #createServer([options][,requestListener]) to mimic original node API#createServer([options][,requestListener] mimics the original function
runsv service plus the #listen() function.#listen() check the options of the original function. Do not include the callback instead, use runsv start event.
runsv service.const runsv = require('runsv').create();
const createService = require('runsv-http');
function listener(req, res){
res.end('hello');
}
const server = createService()
.createServer(listener);
runsv.addService(server);
runsv.start(function(err){
const {port} = services.getClients().http.address();
console.log(`listening at ${port}`);
});
//...
const runsv = require('runsv').create();
const createService = require('runsv-http');
function listener(req, res){
res.end('hello');
}
// As with the original http service we can define
// a listener later...
const server = createService();
runsv.addService(server);
runsv.start(function(err){
const {http} = services.getClients();
// Respond to request events
http.on('request', listener);
const {port} = http.address();
console.log(`listening at ${port}`);
});
//...
#stop(callback) just invokes server.close([callback]).
Bear in mind that stopping (or closing) this service will not terminate the http server immediately.
http-terminator docs explains why.
When you call server.close(), it stops the server from accepting new connections, but it keeps the existing connections open indefinitely. This can result in your server hanging indefinitely due to keep-alive connections or because of the ongoing requests that do not produce a response. Therefore, in order to close the server, you must track creation of all connections and terminate them yourself.
-- http-terminator docs Tracking the connections and terminating them in a gracefully way is beyond the scope of this service wrapper.
There are modules like http-terminator, http-graceful-shutdown or http-close that will do the heavy lifting for you.
// Example: Gracefully terminating connections with http-close
const runsv = require('runsv').create();
const createHTTPService = require('runsv-http');
const httpClose = require('http-close');
const express = require('express');
const app = express();
app.get('/', (req, res) => res.end('hello'));
const httpService = createHTTPService('server').createServer(app);
runsv.addService(httpService);
runsv.start(function(err){
const {server} = runsv.getClients();
// modify server.close behavior to gracefully terminate connections
httpClose({ timeout: 2000 }, server);
});
//...
FAQs
A runsv http server wrapper
We found that runsv-http demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.