
Security News
Meet Socket at Black Hat Europe and BSides London 2025
Socket is heading to London! Stop by our booth or schedule a meeting to see what we've been working on.
@discordx/importer
Advanced tools
A solution to import files on the module and commonjs at the same time
You can use this library without discordx
Support esm and cjs at the same time
Version 16.6.0 or newer of Node.js is required
npm install @discordx/importer
yarn add @discordx/importer
If you use this code with esm or ejs, it will tell you about your environment.
import { isESM } from "@discordx/importer";
console.log(`isESM: ${isESM()}`);
const resolvedPaths = await resolve(`${__dirname}/commands/**.js`);
console.log(resolvedPaths);
Here is an example that could be used with the commonjs or esm modules
importx(`${__dirname}/commands/**.js`).then(() =>
console.log("All files imported"),
);
Remember: In esm, __dirname is not defined, so here is a workaround
import { dirname, importx } from "@discordx/importer";
const __dirname = dirname(import.meta.url);
importx(`${__dirname}/commands/**.js`).then(() =>
console.log("All files imported"),
);
If you are creating a module or extension of your own library, you can set it to auto-import paths based on the user module
import { dirname, importx, isESM } from "@discordx/importer";
const folder = isESM() ? dirname(import.meta.url) : __dirname;
importx(`${folder}/commands/**.js`).then(() =>
console.log("All files imported"),
);
You can use relative path, which will be more convenient to write code by eliminating DIRNAME
import { importx } from "@discordx/importer";
// relative path start from root folder
importx("./tests/commands/**.js").then(() => console.log("All files imported"));
FAQs
A solution to import files on the module and commonjs at the same time
The npm package @discordx/importer receives a total of 501 weekly downloads. As such, @discordx/importer popularity was classified as not popular.
We found that @discordx/importer demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket is heading to London! Stop by our booth or schedule a meeting to see what we've been working on.

Security News
OWASP’s 2025 Top 10 introduces Software Supply Chain Failures as a new category, reflecting rising concern over dependency and build system risks.

Research
/Security News
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.