1.1.8 • Published 5 years ago

revelation-server v1.1.8

Weekly downloads
73
License
-
Repository
-
Last release
5 years ago

https://nodei.co/npm/enoch.png?downloads=true&downloadRank=true&stars=true

Node version contributions welcome NSP Status

Revelation - An Express Middleware to log API requests

Instalation

npm i revelation-server

Usage

At the top of your node file, include this line:

const revelation = require('revelation-server');

Store logs

To store logs, attach the .storeLog() function to the Express route as a middleware either by doing:

app.use('**', revelation.storeLog);

to capture all routes or directly on the route like:

router.post('/example', revelation.storeLog(), (req, res, next) => {
  // Do something

  next();
});

Clean logs

Revelation stores logs as JSON files, in order to clean up old JSON files and prevent excess disk usage, call the cleanup file like so:

revelation.cleanLogs('0 0 * * *', 60);

The 2 parameters to provide are:

  • cron_schedule
  • removal_time_in_days (optional)

So in the above example, this will start a cron job to run every day at midnight and will remove JSON logs which are more than 60 days old.

Serve UI

Revelation has a basic UI which will create a routes named /revelation/logs to be used by the application to fetch the logs and /revelation/reports to fetch the reports. It also creates a subdiretory named /revelation which you can navigate to to view your API logs. Add these routes to your applcication by including the following line in your Node applicaiton.

revelation.serve(app);

Configuration

Revelation will read from a configuration file, .revelation.json, which you can place in the root directory of your project. The following options are available to be configured.

  • secret - Password to be used for UI authentication.

Run in dev mode

To run in dev mode simply clone the repo, navigate to the directory and run npm run dev which will allow you to edit the UI directly with the Angular CLI on port 4000. You can also run npm run prod to serve the UI from the Node.js server. This will run Enoch, including the UI, on your local machine at localhost:8081. You will need to supply some sample logs in the /logs directory.

3rd party integrations

Revelation currently supports external reporting to the following services:

  • Rapid7 Insight - To enable Rapid7 logging, simply make sure you have set RAPID7_ACCESS_TOKEN in your environmental variables.