0
I wish to deploy my node js application on Netlify, inside which I have called a python script.
I have used netlify functions to deploy my node js application. While other endpoints work perfectly fine.
I am not able to execute the endpoint which calls the python script. It crashes with Error - spawn python ENOENT
I have used 2 methods to run python script 1. using child_process 2. using python-shell , both run on my local , but i am not able to deploy it over netlify, I get the following error message
I tried implementing the script on node js and it is working on my local. But it does not deploy on Netlify.
const express = require("express");
const serverless = require("serverless-http");
const cors = require("cors");
const spawn = require("child_process").spawn;
const app = express();
app.use(
cors({
origin: "*",
})
);
const router = express.Router();
router.get("/script", (req, res) => {
var dataToSend;
var childPython = spawn("python", ["script1.py"]);
childPython.stdout.on("data", (data) => {
console.log("Pipe data from python script ...");
dataToSend = data.toString();
});
childPython.on("close", (code) => {
console.log(`child process close all stdio with code ${code}`);
res.send(dataToSend);
});
// res.json({ hello: "hi" });
});
router.get("/about", (req, res) => {
res.json({ hello: "hi" });
});
app.use("/.netlify/functions/python", router);
module.exports.handler = serverless(app);