Categories
Python Answers

How to call a Python function from Node.js?

Spread the love

Sometimes, we want to call a Python function from Node.js.

In this article, we’ll look at how to call a Python function from Node.js.

How to call a Python function from Node.js?

To call a Python function from Node.js, we can use the child_process module.

For instance, we write

const { spawn } = require("child_process");
//...
const pythonProcess = spawn("python", ["path/to/script.py", arg1, arg2]);

to call spawn to run python with the command line arguments in an array.

Conclusion

To call a Python function from Node.js, we can use the child_process module.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *