sleeyax / aternos-discord-bot

Discord bot to start & stop a Minecraft server automatically
https://hub.docker.com/r/sleeyax/aternos-discord-bot/tags
MIT License
79 stars 93 forks source link

Aternos NodeJS #93

Closed xySaad closed 9 months ago

xySaad commented 9 months ago

Is there a way to start the aternos server using NodeJS?

sleeyax commented 9 months ago

Not officially, but you can download and extract the binary from releases, execute it from your Node.js code and optionally stream the output to the console.. Something like this (untested):

const { spawn } = require('child_process');

const child = spawn('aternos-discord-bot');

// use child.stdout.setEncoding('utf8'); if you want text chunks
child.stdout.on('data', (chunk) => {
  console.log(chunk);
});

// since these are streams, you can pipe them elsewhere
child.stderr.pipe(dest);

child.on('close', (code) => {
  console.log(`child process exited with code ${code}`);
});

Source: https://stackoverflow.com/questions/20643470/execute-a-command-line-binary-with-node-js