'kill a running child process in discord.js

I'm trying to kill/access a process. It should start a other bot and also be able to kill it. Here is what I've done.

const { Client,  Intents, DiscordAPIError } = require("discord.js");
const client = new Client({
  intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MEMBERS]
});
const fs = require('fs');
const Discord = require (`discord.js`)
const child = require (`child_process`)

module.exports = {
    name: `start`,
    description: `start the bot`,
    execute(message, args){
        child.exec(`node test.js`, (stderr, stdout) => {
          message.channel.send(`stderr: ${stderr}, stdout: ${stdout}`)
        })

        
}
}

This is the command where I want to stop the bot.

const { Client,  Intents, DiscordAPIError } = require("discord.js");
const client = new Client({
  intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MEMBERS]
});
const fs = require('fs');
const Discord = require (`discord.js`)
const child = require (`child_process`)

module.exports = {
    name: `stop`,
    description: `stop the bot`,
    execute(message, args){
      //no idea what to put here
        })

    




}
}

Can I get the process id or save something in a variable to access the process? Thanks for helping ;)



Solution 1:[1]

This will terminate your program

process.exit()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rajdeep Ray