Issue
Is it possible to call a python script to run server-side by Next.js? I am trying to set up a way to call some python packages I have already developed to be run on my website that is built via React.js + Next.js. I'm hoping to integrate some sklearn methods. Thanks for any suggestions.
Solution
On Server Start
If you want to run the script on Next.js server startup and create a script inside the package.json and run it on before npm start
"scripts": {
"prestart": "sh ./make-coffee.sh",
"start": "next start"
},
From Node.js
If you want to run the script from Node.js(Next.js) code use Child process Doc
const { exec } = require('child_process');
exec('"file/test.sh" arg1 arg2');
REST API
Create REST API for python script and call from next.js server
Answered By - Rahul Sharma
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.