How do I run a file from my main file
Hi there I trying to run a file called clyde.js from my index.js but I don't know the code pls help (This is for a discord bot)
Wumi4 (482)
You can use the exec
function from child_process
.
const { exec } = require("child_process");
exec("node clyde.js", (err, strerr, stdout) => {
if (err) {
console.log(`An error occurred: {err}`);
}
if (stderr) {
console.log(`stderr: {stderr}`);
}
if (stdout) {
console.log(`stdout: {stdout}`);
}
});
RetroBotMaker (0)
@Wumi4 I trying to do it with a discord bot and it does not work
Wumi4 (482)
@RetroBotMaker Oh, so you want to execute the clyde.js
though your Discord bot? Then sorry, I don't know how. But at least, you have learnt that you should give more information to your post, or you will waste your time.
I'm not completely sure, but I hope this helps:
@Andy_4sberg <FUNCTION> ???
@RetroBotMaker, <FUNCTION> must be a function inside clyde.js, you call the function and run it.
@Andy_4sberg I tryed it but is said
"(node:4178) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
/home/runner/Music-Man-Clyde/index.js:67
import code from '/clyde.js'
^^^^^^"
@RetroBotMaker, This worked for me: