express-var-dump

Express view helper that displays all kinds of data (post, query, string, params, cookies, session).

Usage no npm install needed!

<script type="module">
  import expressVarDump from 'https://cdn.skypack.dev/express-var-dump';
</script>

README

express-var-dump

The Express version of PHP's var_dump(). It lets you output information in JSON format regarding cookies, session data, query params, route params, post data and request headers by default.

install

This is a Node.js module available through the npm registry. Installation is done using the npm install command:

npm install express-var-dump

usage

First add the view helper to your app:

// app.js
const { addVarDumpViewHelper } = require('express-var-dump');
const app = require('express')();

// ..define express middleware && other stuff before..

app.use(addVarDumpViewHelper);

// ..define express routing after..

Then in your view call varDump() (using ejs templating engine below):

<!-- views/index.ejs -->
<html>
  <body>
    <%- varDump() %>
  </body>
</html>

Output:

screenshot

advanced usage

varDump(arrayOfProperties, object): html

You can also use varDump directly to generate prettified JSON data to HTML code for any object (in Express it defaults to the request object and the properties detailed in the description).

const { varDump } = require('express-var-dump');
const packageData = require('./package.json');

console.log(varDump(['name', 'version', 'author', 'dependencies'], packageData));
// outputs HTML code generated with `pretty-print-json`

That allows you to use the module with other Node.js web apps that don't use Express.

license

MIT