How do I make a NodeJS Script to do something like os.system on Python? [duplicate]
In Python Script, I can simply make it like this:
import os
import asyncio
async def do_something():
os.system("pip list")
asyncio.run(do_something())
But what about on JavaScript/NodeJS? I see one module named 'os' too in there, but how do I use it?
Solution 1:
You can use the child_process
library to run bash commands. Example below.
import { exec } from "child_process";
exec("pip list", (error, stdout, stderr) => {
console.log(stdout);
})