|
1 |
| -- npm install |
2 |
| -- npm run build |
3 |
| -- npm run start |
| 1 | +# Universal Node.js Example |
4 | 2 |
|
5 |
| -This uses the local version of rollbar in this repository. |
| 3 | +This example demonstrates Rollbar.js in a universal (isomorphic) JavaScript application with both server-side and client-side error tracking. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +A full-stack example featuring: |
| 8 | +- **Server**: Express.js with server-side rendering |
| 9 | +- **Client**: React application with webpack bundling |
| 10 | +- **Universal**: Same error tracking on both server and client |
| 11 | + |
| 12 | +## Setup |
| 13 | + |
| 14 | +```bash |
| 15 | +npm install |
| 16 | +npm run build |
| 17 | +npm start |
| 18 | +``` |
| 19 | + |
| 20 | +## Features |
| 21 | + |
| 22 | +### Server-Side Error Tracking |
| 23 | +- Catches unhandled exceptions in Express routes |
| 24 | +- Tracks errors with request context (user ID, headers, etc.) |
| 25 | +- Demonstrates both error throwing and manual logging |
| 26 | + |
| 27 | +### Client-Side Error Tracking |
| 28 | +- React error boundaries integration |
| 29 | +- Captures browser errors and user interactions |
| 30 | +- Shares configuration between server and client builds |
| 31 | + |
| 32 | +## Routes |
| 33 | + |
| 34 | +- `/` - Main React application |
| 35 | +- `/error` - Triggers a server-side error (demonstrates Express error handling) |
| 36 | +- `/dolog` - Demonstrates manual server-side logging |
| 37 | +- Click "bar" button - Triggers a client-side error |
| 38 | + |
| 39 | +## How It Works |
| 40 | + |
| 41 | +1. **Server** (`server.js`): Initializes Rollbar for Node.js, handles Express errors |
| 42 | +2. **Client** (`app/App.js`): React app that triggers client-side errors |
| 43 | +3. **Webpack**: Bundles client code with Rollbar browser SDK included |
| 44 | +4. **Hot Reload**: Development mode includes webpack hot middleware |
| 45 | + |
| 46 | +## Testing |
| 47 | + |
| 48 | +Visit http://localhost:3000 and: |
| 49 | +- Click the "bar" button to trigger a client-side error |
| 50 | +- Click "Backend error" link to trigger a server-side error |
| 51 | +- Check your Rollbar dashboard to see both errors tracked |
0 commit comments