To download the Express Darkspark plug, use the following:
npm i darkspark-expressjs-plug
To download to a specific directory, follow the guide here. Otherwise, this will automatically download to the node-modules
folder in your root directory.
Move the package to your Express project directory. In the source file in which your express instance is created, require
the downloaded plug:
const {
darkspark,
darksparkVerify,
} = require("../location/of/darkspark_expressjs.js");
The darkspark
function should be called with your Express application as its first argument, and your Darkspark API key as its second argument.
For example,
const app = express();
darkspark(app, "key_abcdef");
The darksparkVerify
function should be included in the verify
option on any body-parser middleware you have installed on your application.
Depending on your setup, this may look like any of the following:
bodyParser.json({
verify: darksparkVerify,
});
bodyParser.urlencoded({
verify: darksparkVerify,
});
app.use(
express.json({
verify: darksparkVerify,
})
);
app.use(
express.urlencoded({
extended: true,
verify: darksparkVerify,
})
);
This completes the setup. The next time you deploy your application, incoming API calls will be captured by Darkspark and populate the Darkspark dashboard.