JavaScript and Node.js errors include the familiar browser-side TypeError, ReferenceError, and SyntaxError, plus a whole set of system-level error codes unique to Node.js. Each entry below covers the error with practical fixes and code examples.
Error Codes
| Error | Description | Fix |
|---|---|---|
| TypeError | Cannot read properties of undefined, or calling a non-function | Add null checks, use optional chaining (?.), and validate data before access |
| ReferenceError | Variable is not defined — using an undeclared variable | Check variable declarations, respect let/const block scope, and avoid the Temporal Dead Zone |
| SyntaxError | Unexpected token — parse-time mistake in brackets, quotes, or syntax | Review the reported line, check for missing brackets, trailing commas, and invalid characters |
| ENOENT (No Such File or Directory) | File not found at runtime in Node.js | Check file paths, use path.join(), handle __dirname, and verify the file exists |
| CORS Error | Blocked by CORS policy — cross-origin request rejected by server | Configure Access-Control-Allow-Origin headers on the server, or use a proxy for development |
Quick Debug
// Catch all unhandled errors (Node.js)
process.on('uncaughtException', (err) => {
console.error('Uncaught Exception:', err);
});
process.on('unhandledRejection', (reason) => {
console.error('Unhandled Rejection:', reason);
});