F
F
Flummox_lnc2021-02-14 23:38:36
Node.js
Flummox_lnc, 2021-02-14 23:38:36

How to call a function from one JS file in another?

I'm making a discord bot (well, how I do it... I'm trying), and when creating commands, they began to clutter up the on-line file with the code, there were a lot of commands. And accordingly, I decided that it is possible to place each command in a separate file, and then call them from the main one as a function for example (from C # experience). But in Google, on this matter, information is only about web pages, and I need to activate the code in another file from the main file so that it does its job, send a message, for example.

Maybe this is a difficult question, or even more like an order for a freelancer, but if it’s not difficult for you, tell me how to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alvvi, 2021-02-14
@Flummox_lnc

// index.js
import { commandA } from 'commandA.js';
import { commandB } from 'commandB.js';

commandA();
commandB();

// commandA.js
export function commandA() {}

// ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question