The library is most useful when trying to use your own or private code that was written for Node.js. If you are trying to consume public npm packages, you are likely to get a better result using a .

    The standard library provides several “replacement” modules for Node.js built-in modules. These either replicate the functionality of the built-in or they call the Deno native APIs, returning an interface that is compatible with Node.js.

    In addition, there is the std/node/global.ts module which provides some of the Node.js globals like global, process, and Buffer.

    If you want documentation for any of the modules, you can simply type deno doc and the URL of the module in your terminal:

    Loading CommonJS modules

    That being said, the built-in Node.js module "module" provides a function named createRequire() which allows you to create a Node.js compatible require() function which can be used to load CommonJS modules, as well as use the same resolution logic that Node.js uses when trying to load a module. createRequire() will also install the Node.js globals for you.

    Example usage would look like this:

    1. import { createRequire } from "https://deno.land/std@$STD_VERSION/node/module.ts";
    2. // import.meta.url will be the location of "this" module (like `__filename` in
    3. // Node.js), and then serve as the root for your "package", where the
    4. // for resolution of packages.
    5. const require = createRequire(import.meta.url);
    6. // Loads the built-in module Deno "replacement":
    7. const path = require("path");
    8. // Loads a CommonJS module (without specifying the extension):
    9. const cjsModule = require("./my_mod");
    10. // Uses Node.js resolution in `node_modules` to load the package/module. The
    11. // package would need to be installed locally via a package management tool
    12. // like npm: