Enterprise-grade error tracking SDK for Node.js/Express backends and browser frontends.
npm install sniplogconst express = require('express');
const SnipLog = require('sniplog');
const app = express();
// Initialize SnipLog
const sniplog = new SnipLog({
endpoint: 'http://localhost:3000/api/errors',
projectKey: 'your-project-key',
autoCaptureExceptions: true, // Auto-capture uncaught exceptions
timeout: 5000
});
// Add request middleware (adds req.sniplog helper)
app.use(sniplog.requestMiddleware());
// Your routes here...
// Add error middleware - MUST be after all routes
app.use(sniplog.errorMiddleware());
app.listen(3000);const sniplog = new SnipLog({
endpoint: 'http://localhost:3000/api/errors', // SnipLog backend URL
projectKey: 'your-api-key', // Project API key
autoCaptureExceptions: true, // Auto-capture process errors (default: true)
enabled: true, // Enable/disable SDK (default: true)
timeout: 5000, // Request timeout in ms (default: 5000)
discordWebhook: 'https://discord.com/api/webhooks/...' // Optional: Discord webhook URL
});app.get('/api/data', async (req, res) => {
try {
const data = await fetchData();
res.json(data);
} catch (err) {
// Capture error with context
req.sniplog.captureError(err, {
userId: req.user?.id,
operation: 'fetch-data',
endpoint: '/api/data'
});
res.status(500).json({ error: 'Failed to fetch data' });
}
});app.post('/api/users', (req, res) => {
req.sniplog.captureMessage('New user registration attempt', {
level: 'info',
email: req.body.email
});
// ... handle registration
});Request Middleware (sniplog.requestMiddleware())
- Adds
req.sniplog.captureError()andreq.sniplog.captureMessage()helpers - Automatically includes request context (method, URL, IP, user-agent)
Error Middleware (sniplog.errorMiddleware())
- Captures all errors that reach Express error handlers
- Includes full request context
- Must be placed AFTER all routes and middleware
When autoCaptureExceptions: true:
uncaughtExceptionevents are capturedunhandledRejectionevents are captured
Each captured error includes:
- Error message and stack trace
- System info (Node version, OS, hostname)
- Process ID and session ID
- Custom metadata you provide
See example-express-app.js for a full working example.
To run the example:
# Start the SnipLog backend first (in another terminal)
cd backend
npm start
# Run the example app
cd sdk
node example-express-app.js
# Test error capture
curl http://localhost:4000/test-errorFor frontend integration, include browser.js directly:
<script src="/path/to/sniplog/src/browser.js"></script>
<script>
SnipLog.init({
endpoint: 'http://localhost:3000/api/errors',
projectKey: 'your-project-key'
});
</script>The browser SDK will automatically capture:
window.onerror(script errors)unhandledrejection(promise rejections)console.error(optional)
Creates a new SnipLog instance.
Parameters:
config.endpoint(string): SnipLog backend URLconfig.projectKey(string): Your project API keyconfig.autoCaptureExceptions(boolean): Auto-capture process errors (default: true)config.enabled(boolean): Enable/disable SDK (default: true)config.timeout(number): Request timeout in ms (default: 5000)config.discordWebhook(string): Optional Discord webhook URL for real-time notifications
Manually capture an error.
Parameters:
error(Error): The error objectmetadata(object): Additional context (userId, operation, etc.)
Capture a non-error message/event.
Parameters:
message(string): The messagemetadata(object): Additional context
Returns Express middleware that adds req.sniplog helpers.
Returns Express error handling middleware. Place after all routes.
SnipLog supports real-time error notifications via Discord webhooks. Errors will be sent to both the backend database AND your Discord channel.
- Open Discord and go to your server
- Go to Server Settings > Integrations > Webhooks
- Click New Webhook or Create Webhook
- Copy the Webhook URL
const sniplog = new SnipLog({
endpoint: 'http://localhost:3000/api/errors',
projectKey: 'your-api-key',
discordWebhook: 'https://discord.com/api/webhooks/1234567890/your-webhook-token'
});Alternatively, configure Discord webhook in the backend (all projects will use it):
.env file:
DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/1234567890/your-webhook-tokenWhen an error occurs, you'll receive a Discord message like:
π¨ **expressError**: Cannot read property 'id' of undefined
π
**Time**: 10/31/2025, 3:45:12 PM
π **URL**: /api/users/123
π **Method**: GET
π» **Host**: production-server
π€ **User**: user-456
Error: Cannot read property 'id' of undefined at getUserProfile (/app/routes/users.js:45:20) at Layer.handle [as handle_request] at next (/app/node_modules/express/lib/router/route.js:137:13)
- β Real-time notifications in Discord
- β Formatted with emojis and markdown
- β Includes error message, stack trace, and metadata
- β Truncated to fit Discord's 2000 character limit
- β Works for both SDK and backend configurations
sdk/
βββ src/
β βββ index.js # Auto-detects environment (Node/browser)
β βββ node.js # Node.js/Express SDK
β βββ browser.js # Browser SDK (for future frontend use)
βββ example-express-app.js
βββ package.json
βββ README.md
# Link SDK locally
cd sdk
npm link
# Use in your project
cd your-express-app
npm link sniplogWe welcome contributions! If you'd like to improve the SDK, please open an issue or submit a pull request.
For details, see our CONTRIBUTING.md guide.
Thanks for helping make SnipLog better!
MIT