server.js code ---------------------------------------------- const express = require("express"); const { spawn } = require("child_process"); const app = express(); app.use(express.json()); app.use(express.static("public")); app.post("/ask", (req, res) => { const question = req.body.question; const py = spawn("python", ["bot.py", question]); let answer = ""; py.stdout.on("data", data => { console.log("PY OUT:", data.toString()); answer += data.toString(); }); py.stderr.on("data", data => { console.log("PY ERR:", data.toString()); }); py.on("close", () => { console.log("FINAL ANSWER:", answer); res.json({ answer }); }); }); app.listen(3000, () => { console.log("Server running http://localhost:3000"); }); _____________________________________________ bot.js import sys import ollama question = sys.argv[1] response = ollama.chat( model="gemma3:4b", messages=[ {"role": "user", "content": question} ] ) text = response["message"]["content"] # remove emojis / non-ascii (Windows fix) text = text.encode("ascii", "ignore").decode() print(text, flush=True) _________________________________________ chatbot/public/index.html ----------------------------------------

Simple AI Chat








_____________________________________

some explanation


๐Ÿ”น spawn(...)

spawn Node.js ka function hota hai (from child_process)
Iska kaam: bahar ka program chalana โ€” yahan Python.

Matlab:
๐Ÿ‘‰ Node โ†’ Python ko bol raha hai: โ€œbhai script chalaoโ€

๐Ÿ”น "python"

Ye batata hai kaunsa program run karna hai:

"python"


= system ka Python interpreter.


Python side pe:

import sys
question = sys.argv[1]


Ye wahi question hai ๐Ÿ‘

Flow samjho: