Opinionated Express.js HTTP Server Resource
raw JSON →The `resource-http` library provides an opinionated framework for quickly setting up an HTTP server based on Express.js. It bundles common web application functionalities such as static file serving, user sessions, HTTPS/SSL, WebSockets, OAuth authentication (via Passport), view rendering (via the `view` module), i18n support (via `i18n-2`), and body parsing, all configurable through a single options object. Currently at version 1.3.0, the package appears to be unmaintained, with its last publish date in 2014 and explicitly relying on Express 4.x.x, which is a significantly outdated version of Express. Its core value lies in abstracting away individual middleware integrations for rapid prototyping, but its age makes it unsuitable for modern production environments.
Common errors
error TypeError: require is not a function ↓
"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 Error: Can't set headers after they are sent to the client ↓
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. error ERR_OSSL_EVP_UNSUPPORTED ↓
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. Warnings
breaking This package is abandoned and has not been updated since 2014. It relies on Express 4.x.x, which is severely outdated and contains numerous known security vulnerabilities. Using this package in any production environment is strongly discouraged due to unpatched security flaws in its core dependencies and the package itself. ↓
security The `nodeinfo` and `nodeadmin` options (if set to `true`) expose sensitive system information and administrative interfaces via HTTP routes (`/_info`, `/_iadmin`). Enabling these options on an unsecured server creates a critical security vulnerability, allowing unauthorized access to server diagnostics and control. This risk is compounded by the package's abandonment. ↓
deprecated The package's reliance on Express 4.x.x means it does not support modern Node.js features, ES Modules, or the latest Express API paradigms. Many common middleware and practices have evolved significantly since its last update. ↓
gotcha All third-party dependencies mentioned in the README (e.g., `passport`, `view`, `i18n-2`, `connect-redis`) are likely also outdated and may have their own security vulnerabilities or compatibility issues with newer Node.js versions. These dependencies are not explicitly listed in the `package.json` for `resource-http` itself, meaning you might have to manually install very old, insecure versions. ↓
Install
npm install resource-http yarn add resource-http pnpm add resource-http Imports
- http wrong
import http from 'resource-http';correctconst http = require('resource-http'); - listen wrong
import { listen } from 'resource-http';correctconst http = require('resource-http'); http.listen({ port: 8080 }, (err, app) => { /* ... */ }); - app wrong
const app = require('resource-http').app;correctconst http = require('resource-http'); http.listen({ port: 8080 }, (err, app) => { // `app` is an Express application instance app.get('/', (req, res) => res.send('Hello')); });
Quickstart
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!');
});
});