2.0.0 • Published 3 months ago

node-gnu-clacks v2.0.0

Weekly downloads
7
License
MIT
Repository
github
Last release
3 months ago

Node/Express GNU Clacks

A man is not dead while his name is still spoken. Add an 'X-Clacks-Overhead' Header to your vanilla Node or Express app.

See http://www.gnuterrypratchett.com

npm npm license

Install

  • Install with npm or download and create your own module.
npm install node-gnu-clacks --save

Usage

  • Import the module and tell your app to use as middleware:
const { node: gnuHeaderNode } = require('node-gnu-clacks');
const { express: gnuHeaderExpress } = require('node-gnu-clacks');

note: you can also use const gnuHeader = require('node-gnu-clacks'); for express apps for backwards compatibility with v1.

Options

string[] ghosts = 'Terry Pratchett'

Add an array of names to be passed. This is in addition to the default, 'Terry Pratchett', which will always be added.

Example with a vanilla Node app

const http = require('http');
const { node: gnuHeaderNode } = require('node-gnu-clacks');

http.createServer((req, res) => {
    const addClacksHeader = gnuHeaderNode(['Moist', 'Adora', 'Reacher']);
    addClacksHeader(res);
    
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('A man is not dead while his name is still spoken.\n');
}).listen(3000);

Example with an Express app

const express = require('lib/express');
const { express: gnuHeaderExpress } = require('node-gnu-clacks');

const app = express();

app.use(gnuHeaderExpress());
or
app.use(gnuHeaderExpress(['Moist', 'Adora', 'Reacher']));

app.get('/', (req, res) => {
    res.send('A man is not dead while his name is still spoken.');
});

app.listen(3000);