Skip to content

mdipanjan/node-telescope

Folders and files

NameName
Last commit message
Last commit date

Latest commit

41c61e6 Β· Sep 5, 2024

History

80 Commits
Jul 31, 2024
Jul 17, 2024
Aug 3, 2024
Sep 5, 2024
Jul 25, 2024
Jul 17, 2024
Jul 25, 2024
Jun 28, 2024
Jul 17, 2024
Jul 17, 2024
Jul 18, 2024
Jul 17, 2024
Jul 18, 2024
Jul 18, 2024
Sep 5, 2024
Jul 3, 2024
Jun 30, 2024
Aug 1, 2024
Jul 26, 2024

Repository files navigation

Node Telescope

npm version License: MIT

Node Telescope is a comprehensive logging and monitoring solution for Node.js applications. It provides real-time insights into your application's performance, errors, and database queries, with support for both MongoDB and PostgreSQL.

Banner

Banner

πŸš€ Features

  • Real-time request logging
  • Exception tracking with stack traces
  • Database query monitoring (MongoDB and PostgreSQL)
  • Memory usage tracking
  • WebSocket support for live updates
  • Customizable storage options
  • Easy integration with Express applications
  • Configurable response body and query result size limits
  • Frontend dashboard for data visualization

πŸ“¦ Packages

This monorepo contains the following packages:

πŸ› οΈ Installation

To use Node Telescope in your project, install it via npm:

npm install node-telescope

For the frontend dashboard:

npm install node-telescope-frontend

🚦 Quick Start

Here's a basic example of how to integrate Node Telescope into your Express application:

import express from 'express';
import mongoose from 'mongoose';
import dotenv from 'dotenv';
import cors from 'cors';
import { Telescope, MongoStorage, EntryType, TelescopeDatabaseType } from 'node-telescope';
import { createServer } from 'http';

dotenv.config();

async function createServer() {
	const app = express();
	const server = createServer(app);

	// Middleware
	app.use(express.json());
	app.use(cors());

	// Connect to MongoDB
	await mongoose.connect(process.env.DB_URI || '');
	console.log('Connected to MongoDB');

	// Configure Telescope
	const storage = new MongoStorage({
		connection: mongoose.connection,
		dbName: process.env.DB_NAME || 'telescope',
	});

	const telescope = new Telescope({
		storage: storage,
		watchedEntries: [EntryType.REQUESTS, EntryType.EXCEPTIONS, EntryType.QUERIES],
		enableQueryLogging: true,
		app: app,
		server: server,
		databaseType: TelescopeDatabaseType.MONGO,
		includeCurlCommand: true,
	});

	app.use(telescope.middleware());

	// Routes
	app.get('/', (req, res) => {
		res.send('Hello World! This is the TestServer.');
	});

	app.get('/error', (req, res) => {
		throw new Error('This is a test error');
	});

	// Error handling
	app.use((err, req, res, next) => {
		console.error(err.stack);
		res.status(500).send('Something broke!');
	});

	return server;
}

// Create and start the server
(async () => {
	try {
		const server = await createServer();
		const PORT = process.env.PORT || 4000;
		server.listen(PORT, () => {
			console.log(`Server is running on http://localhost:${PORT}`);
			console.log(`Telescope is available at http://localhost:${PORT}/telescope`);
		});
	} catch (error) {
		console.error('Failed to start the server:', error);
		process.exit(1);
	}
})();

πŸ“š Documentation

For detailed usage instructions and API documentation, please refer to the following resources:

πŸ§ͺ Examples

Check out our example projects for different setup scenarios:

🀝 Contributing

We welcome contributions! Please see our Contributing Guide for more details on how to get started.

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgements

This project was inspired by Laravel Telescope, a powerful debug assistant for the Laravel framework.


Built with ❀️ by mdipanjan