Install the errsole and errsole-mongodb modules using the npm install command:
npm install errsole errsole-mongodb
// CommonJS
const errsole = require('errsole');
const ErrsoleMongoDB = require('errsole-mongodb');
// ESM and TypeScript
import errsole from 'errsole';
import ErrsoleMongoDB from 'errsole-mongodb';
// Insert the Errsole code snippet at the beginning of your app's main file
errsole.initialize({
storage: new ErrsoleMongoDB('<MongoDB Connection URL>', '<Optional: Database Name>', '<Optional: MongoDB Client Options>')
});
const express = require('express');
const errsole = require('errsole');
const ErrsoleMongoDB = require('errsole-mongodb');
// Insert the Errsole code snippet at the beginning of your app's main file
errsole.initialize({
storage: new ErrsoleMongoDB('mongodb://localhost:27017/', 'logs')
});
const app = express();
app.get('/', function (req, res) {
res.send('Hello World');
});
app.listen(3000);