Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
http
✓ const http = require('resource-http');
✗ import http from 'resource-http';
This package is CommonJS-only and relies on the `require()` syntax. Direct ES Module `import` syntax will not work without a CommonJS-to-ESM wrapper or a custom Node.js loader configuration. The imported `http` object directly exposes the `listen` function and other utilities.
listen
✓ const http = require('resource-http');
http.listen({ port: 8080 }, (err, app) => { /* ... */ });
✗ import { listen } from 'resource-http';
The `listen` function is a property of the main exported `http` object, not a named export. Attempting to destructure it as a named export from an ES Module import will fail due to the package's CJS nature.
app
✓ const http = require('resource-http');
http.listen({ port: 8080 }, (err, app) => {
// `app` is an Express application instance
app.get('/', (req, res) => res.send('Hello'));
});
✗ const app = require('resource-http').app;
The Express `app` instance is exposed via the callback of the `http.listen` function, not directly as an export from the package. It is an instance of an Express 4.x.x application.
This example demonstrates how to initialize and configure an HTTP server using `resource-http`, including basic routing and common options like WebSockets and session management. It creates an Express app instance and attaches a simple GET route.
const http = require('resource-http');
const fs = require('fs');
// all options are optional and will default to a reasonable value if left unset
http.listen({
port: 8888,
wss: true, // enables websocket server
host: 'localhost',
root: __dirname + "/public",
view: __dirname + "/view",
cacheView: true, // caches all local view templates and presenters into memory
uploads: false,
https: false, // enables https / ssl, requires key, cert, ca
autoport: true, // will auto-increment port if port unavailable
bodyParser: true, // parse incoming body data automatically, disable for streaming
sslRequired: false, // redirects all http traffic to https
onlySSL: false, // will only start https server, no http services
noSession: false, // removes all session handling from server
nodeinfo: false, // makes /_info route available for node information
nodeadmin: false, // makes /_iadmin route available for node administration
// For HTTPS, you would need to provide actual key, cert, and ca files:
// key: fs.readFileSync(__dirname + "/ssl/server.key").toString(),
// cert: fs.readFileSync(__dirname + "/ssl/cert.crt").toString(),
// ca: fs.readFileSync(__dirname + "/ssl/ca.crt").toString(),
secret: "supersecret", // session password
redis: { // optional redis store for sessions, requires `connect-redis` package
host: "0.0.0.0",
port: 6379,
password: "foobar" // replace with process.env.REDIS_PASSWORD ?? '' in production
},
auth: {
basicAuth: {
username: 'admin',
password: 'admin' // replace with process.env.ADMIN_PASSWORD ?? '' in production
}
}
}, function(err, app){
if (err) {
console.error('Server failed to start:', err);
return;
}
console.log('Server listening on', app.server.address());
// from here, app is a regular Express.js server
app.get('/foo', function (req, res){
res.end('got /foo');
});
app.get('/', function (req, res){
res.end('Hello from resource-http!');
});
});
Errors
Common errors & fixes
TypeError: require is not a function
Attempting to use `require()` in an ES Module (ESM) context when `resource-http` is a CommonJS (CJS) module.
fixEnsure your project is configured for CommonJS (e.g., remove `"type": "module"` from `package.json`, or use a transpiler like Babel). If using Node.js, you might need to use a dynamic import `import('resource-http')` or a CJS wrapper, but this package is too old to guarantee compatibility. Error: Can't set headers after they are sent to the client
This is a common Express.js error, often indicating that a response was already sent (e.g., `res.send()`, `res.end()`, `res.json()`) before another attempt to modify the headers or send another response was made. This can be more prevalent with older, less robust middleware.
fixCarefully review your route handlers and middleware to ensure that `res.send()`, `res.end()`, or similar response-sending methods are called only once per request-response cycle. Use `return` after sending a response to prevent further execution in the handler.
ERR_OSSL_EVP_UNSUPPORTED
Occurs with Node.js 17+ when using older OpenSSL features, often triggered by outdated HTTPS/SSL configurations or certificates generated with deprecated algorithms, which this older package might default to or expect.
fixIf this error occurs, try setting `NODE_OPTIONS=--openssl-legacy-provider` when running Node.js (e.g., `NODE_OPTIONS=--openssl-legacy-provider node server.js`). This is a temporary workaround; the long-term fix is to update certificates and cryptographic algorithms to modern standards, or, ideally, migrate from this abandoned package.
Audit
Dependencies
expressrequiredCore HTTP server framework (specifically Express 4.x.x).
passportrequiredOAuth Single Sign On (SSO) functionality.
viewrequiredView template rendering support.
i18n-2requiredInternationalization (i18n) support.
connect-redisoptionalOptional Redis store for session management.