I was tired of getting the generic configuration data out by log and inspect. This is a drop in file, working with IIS (issnode) as well.
npx node-infopage
npm i -g node-infopage
$ PORT=4567 node-infopage
PS $ENV:PORT=4567 ; node-infopage
\> set PORT=4567 && node-infopage
Does also work with npx
, just put npx
right before node-infopage
.
// ESM:
import {server} from 'nodeinfopage';
server(..optionalPort..);
// old require way
require('node-infopage').server(..optionalPort..);
// ESM:
import {getInfoHtml} from 'nodeinfopage';
let html = getInfoHtml(request, response);
// old require way
let html = require('node-infopage').getInfoHtml(request, response);
You can use it with express, koa and others. The request
and response
objects can be anything.
import {getInfoHtml} from 'nodeinfopage';
//const app = new (require('http').Server)();
import Server from 'http';
let app = new Server();
app.on('request', (request, response) => {
res.writeHead(200, { 'Content-Type': 'text/html' });
let html = getInfoHtml(request, response);
res.send( html ); // or how ever your own server needs the html
res.end('\n');
});
app.listen(8888);
If port is omitted, on server()
function, default is 4567
If started standalone, process.env.INFOPAGE_PORT
, then process.env.NODE_PORT
, then process.env.PORT
is checked, then fallback to default 4567