2

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?

Interesting
  • 255
  • 1
  • 4
  • 16
  • 2
    Does this answer your question? [Execute a command line binary with Node.js](https://stackoverflow.com/questions/20643470/execute-a-command-line-binary-with-node-js) – KyleRifqi Jan 23 '22 at 04:54

1 Answers1

2

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);
})
carlosdafield
  • 1,479
  • 5
  • 16