简体   繁体   中英

Can you run a node.js code on java script

I have a js code, basically a discord bot code, so usually need to do to run this bot is open cmd in the js path and do node {file_name}.js , so now suppose I have a java script code that I wish to run on button click and send a message box when it starts running, how would I do that. This is my JS Code

const Discord=require("discord.js"),
client=new Discord.Client;
client.on("ready", () => {
console.log(`Logged in as ${client.user.tag}!`)});

client.on("message", e => {
"ping" === e.content && e.reply("Pong!");
});

client.login("token");

Also if possible would like to have the code in the application code itself, something like this

string code = "const Discord=require("discord.js"),
client=new Discord.Client;
client.on("ready", () => {
console.log(`Logged in as ${client.user.tag}!`)});

client.on("message", e => {
"ping" === e.content && e.reply("Pong!");
});

client.login("token");";

Answers are appreciated, thank you for reading:) Have a good day

I think you will be able to have the answer here: Is it possible to run a Node script from a web page?

The best way I suppose is to call an express server and this one will call your node script.

Hope this will help;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM