π§ Building a Lightweight LLM-Powered Q&A API Using Ollama and Node.js | by Raviya Technical | AdonisJS | Jul, 2025

Modern AI applications often require integrating local or hosted Large Language Models (LLMs) into web backends. In this article, we walk through the structure of a simple yet efficient Node.js API that leverages Ollama for running LLMs like Mistral locally. This setup enables asking questions based on a predefined text file using chunking and keyword matching.
project-root/
βββ src/
β βββ config/
β β βββ llms.js # LLM configuration
β βββ controllers/
β β βββ api/
β β βββ llmsController.js # Core logic for question answering
β βββ services/
β β βββ llms/
β β βββ ollamaService.js # Communication with Ollama API
β βββ utils/
β β βββ llms.js # Text chunking and relevance logic
β β βββ utils.js # Utility functions (loadTXT, apiResponse)
β βββ routes/
β β βββ api/
β β βββ llms.routes.js # API route definition
βββ uploads/
βββ docs/
βββ example.txt # The source document for Q&A
This config file defines the model and chunking parameters used for splitting documents into manageable pieces.
module.exports = {
OLLAMA_URL: "http://localhost:11434",
MODEL_NAME: process.env.MODEL_NAME || "mistral",
// CHUNK_SIZE: 1000,
// OVERLAP: 100,
CHUNK_SIZE: 300,
OVERLAP: 50,
};
