Node.js Error Tracking
DebugMate captures common Node.js errors, helping developers handle core runtime issues efficiently. Below is an overview of frequently encountered Node.js errors and their context.
Tracked Errors
Simple Exception: A general exception not tied to a specific error type, often used for generic errors.
Syntax Error: Indicates an error in the code syntax, often occurring due to miswritten commands.
Undefined Variable: A variable referenced in the code that has not been defined, leading to runtime errors.
Method Not Found: Triggered when a called method does not exist within the scope, leading to undefined behavior.
File Not Found: Indicates that a specified file cannot be located or accessed.
Null Reference Error: Occurs when attempting to access a property or method on a null or undefined object.
Type Error: Raised when a variable or parameter is not of the expected type, common in type-sensitive operations.
Reference Error: Occurs when a variable or function is referenced that has not been declared.
Range Error: Indicates a value not within the permissible range, often seen with arrays or numeric operations.
Installation Process
1. Add module as a local dependency(while we're still developing)
file: package.json
"dependencies": {
"debugmate": "file:<place-here-you-clone-the-repo>"
}
2. Install dependencies
npm install
3. Create .env
file in the root project if you don't have one and add the following variables
DEBUGMATE_DOMAIN=http://debugmate-app.test
DEBUGMATE_TOKEN='your-token'
DEBUGMATE_ENABLED=true
4. Add test script to package.json
"scripts": {
"debugmate:test": "node ./node_modules/debugmate/scripts/connectionTest.js"
}
5. Run script test
You're able to send a fake error to the Debugmate as a test by running this command:
npm run debugmate:test
Usage
1. Report Errors
In the class where you want report the error import the module and call the debugmate.publish(error)
method
const debugmate = require('debugmate/debugmate')
try {
// ...error producing code
} catch (error) {
debugmate.publish(error)
}
You can also report errors by calling debugmate.publish(error)
method using process.on('uncaughtException', (error) => {})
process.on('uncaughtException', (error) => {
debugmate.publish(error)
})
2. Report Errors and Request Data
//Some method that throws an error and has a request object
try {
// ...error producing code
} catch (error) {
debugmate.publish(error, request)
}
3. Report Context Data
If you want to send more information to the Debugmate:
- Create
debugmateContext.cjs
file in the root project and create the getUser and getEnvironment methods. These methods will be called by the Debugmate to get the data you want to send. - Add
DEBUGMATE_CONTEXT
to your .env file with the path of the appContext.js file.
// file: debugmateContext.cjs
function getUser() {
// Retrieve user data the way you want
const user = {
id: 1,
name: 'John Doe',
email: '[email protected]',
}
// Return the user data as an object to Debugmate
return user
}
function getEnvironment() {
const environment = {
environment: 'local',
debug: true,
timezone: 'UTC',
server: 'apache',
database: 'mysql 5.7',
npm: '6.13.4',
}
return environment
}
module.exports = { getUser, getEnvironment }
// file: .env
DEBUGMATE_CONTEXT=/path/root/project/debugmateContext.cjs