@gpt-flow/node
v1.0.7
Published
Node.js middleware for logging errors to GPT-Flow
Downloads
2
Readme
@gpt-flow/node
A Node.js package to capture and send logs to the GPT-Flow API for processing and analysis.
Step 1: Installation
Install the package using npm:
npm install @gpt-flow/node
Step 2: Setting Up the Configuration
You have two options for setting up the configuration: using environment variables or configuring it programmatically.
Option 1: Environment Variables
If you prefer to use environment variables, create a .env
file in your project’s root directory and add the following variables:
PROJECT_ID=your_project_id
PUBLIC_KEY=your_public_key
PROJECT_URL=https://gpt-flow-llm-api.onrender.com
Make sure to replace the placeholders with your actual project details.
Option 2: Programmatic Configuration
Alternatively, you can directly configure the package in your application code:
const gptFlow = require('@gpt-flow/node');
// Initialize with your project settings
gptFlow.init({
projectId: 'your_project_id', // Replace with your project ID
publicKey: 'your_public_key', // Replace with your public key
projectUrl: 'https://gpt-flow-llm-api.onrender.com', // Replace with GPT-Flow URL
});
Step 3: Using the Package in a Node.js Application
Once your configuration is set, you can use the GPT-Flow package to capture errors or logs in your Node.js application.
Here’s an example of how you could integrate it into an HTTP server:
const http = require('http');
const gptFlow = require('@gpt-flow/node');
// Initialize GPT-Flow with your project configuration
gptFlow.init({
projectId: process.env.PROJECT_ID || 'your_project_id', // Replace with your project ID
publicKey: process.env.PUBLIC_KEY || 'your_public_key', // Replace with your public key
projectUrl: process.env.PROJECT_URL || 'https://gpt-flow-llm-api.onrender.com', // Replace with GPT-Flow URL
});
// Create a basic HTTP server
const server = http.createServer((req, res) => {
if (req.url === '/') {
// Simulate an error for logging purposes
throw new Error('Simulated error for logging');
}
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello, World!');
});
// Handle server errors and log them to GPT-Flow
server.on('error', (err) => {
gptFlow.sendLogs({
message: err.message,
stack: err.stack,
method: 'GET',
url: '/',
});
});
// Start the server
server.listen(3000, () => {
console.log('Server is running on http://localhost:3000');
});
This setup will capture errors from your Node.js application and send the logs to the GPT-Flow API.