UNPKG

node-ai-chatbot-cli

Version:

A lightweight Node.js package and CLI tool that allows developers to easily interact with OpenAI's ChatGPT API. Supports automated API key setup, simple chatbot creation, and seamless integration into JavaScript applications. Ideal for building AI-powered

22 lines (16 loc) • 610 B
const fs = require('fs'); const path = require('path'); const prompt = require('prompt-sync')(); const envPath = path.join(__dirname, '.env'); if (fs.existsSync(envPath)) { console.log("āœ… .env file already exists. Skipping API key setup."); process.exit(0); } console.log("\nšŸ”‘ Welcome to chatgpt-chatbot setup!"); const apiKey = prompt("Enter your OpenAI API Key: "); if (!apiKey) { console.error("āŒ API Key is required! Exiting..."); process.exit(1); } fs.writeFileSync(envPath, `OPENAI_API_KEY=${apiKey}\n`); console.log("āœ… API Key saved successfully!\n");