{"library":"resource-http","title":"Opinionated Express.js HTTP Server Resource","description":"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.","language":"javascript","status":"abandoned","last_verified":"Thu Apr 23","install":{"commands":["npm install resource-http"],"cli":null},"imports":["const http = require('resource-http');","const http = require('resource-http');\nhttp.listen({ port: 8080 }, (err, app) => { /* ... */ });","const http = require('resource-http');\nhttp.listen({ port: 8080 }, (err, app) => {\n  // `app` is an Express application instance\n  app.get('/', (req, res) => res.send('Hello'));\n});"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const http = require('resource-http');\nconst fs = require('fs');\n\n// all options are optional and will default to a reasonable value if left unset\nhttp.listen({\n  port: 8888,\n  wss: true, // enables websocket server\n  host: 'localhost',\n  root: __dirname + \"/public\",\n  view: __dirname + \"/view\",\n  cacheView: true, // caches all local view templates and presenters into memory\n  uploads: false,\n  https: false, // enables https / ssl, requires key, cert, ca\n  autoport: true, // will auto-increment port if port unavailable\n  bodyParser: true, // parse incoming body data automatically, disable for streaming\n  sslRequired: false, // redirects all http traffic to https\n  onlySSL: false, // will only start https server, no http services\n  noSession: false, // removes all session handling from server\n  nodeinfo: false, // makes /_info route available for node information\n  nodeadmin: false, // makes /_iadmin route available for node administration\n  // For HTTPS, you would need to provide actual key, cert, and ca files:\n  // key: fs.readFileSync(__dirname + \"/ssl/server.key\").toString(),\n  // cert: fs.readFileSync(__dirname + \"/ssl/cert.crt\").toString(),\n  // ca: fs.readFileSync(__dirname + \"/ssl/ca.crt\").toString(),\n  secret: \"supersecret\", // session password\n  redis: { // optional redis store for sessions, requires `connect-redis` package\n    host: \"0.0.0.0\",\n    port: 6379,\n    password: \"foobar\" // replace with process.env.REDIS_PASSWORD ?? '' in production\n  },\n  auth: {\n    basicAuth: {\n      username: 'admin',\n      password: 'admin' // replace with process.env.ADMIN_PASSWORD ?? '' in production\n    }\n  }\n}, function(err, app){\n  if (err) {\n    console.error('Server failed to start:', err);\n    return;\n  }\n  console.log('Server listening on', app.server.address());\n  // from here, app is a regular Express.js server\n  app.get('/foo', function (req, res){\n    res.end('got /foo');\n  });\n  app.get('/', function (req, res){\n    res.end('Hello from resource-http!');\n  });\n});","lang":"javascript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}