0

I have node.js installed and want to know if there is any way to run js code on python 3.8. I need to use a large piece of code (babylon) for my web application. Is there any easy way to do this?

2 Answers 2

1

Running Code

I admit I have not messed with this before, but I think the best way to go about it is to have a js file that you can run from python. I found 2 ways to accomplish this- one that returns output and one that simply just runs it.

Getting Output

You may be able to use the subprocess module to run the node and record it's output for later use.

import subprocess
myValue = subprocess.check_output(['node','index.js'])

Python subprocess.check_output Documentation

No Output

If you do not require to read the output of the file, you can just run it with the os module.

import os
os.system("node index.js")

Python os.system documentation

Sign up to request clarification or add additional context in comments.

Comments

0

I do like the answer given. I would like to add that one could use the Naked library:

from Naked.toolshed.shell import execute_js
execute_js('file.js')

One can read more here: https://naked.readthedocs.io/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.